diff --git a/doc/userdoc.org b/doc/userdoc.org index 1eaa03f39e54ff95f6d0ed0371f188bfb2f3c7ff..207e283d659d949d6310943b4af6f71a838f1854 100644 --- a/doc/userdoc.org +++ b/doc/userdoc.org @@ -1269,6 +1269,8 @@ The ~pugs~ language allows the following tokens as unary operators |----------+----------------------| | ~++~ | increment operator | | ~--~ | decrement operator | +|----------+----------------------| +| ~[]~ | access operator | The ~not~, ~+~ and ~-~ operators apply to the *expression* on their right. ~++~ and ~--~ operators apply only to a *variable* that can be positioned @@ -1283,11 +1285,11 @@ For basic types, when these operators are defined, they return a value of the same type as the argument (except if the argument is a ~N~, then the result is a ~Z~). These operators can be defined for high-level types. -- The ~not~ operator is only defined for boolean values (~B~) -- the ~-~ unary operator is defined for numeric basic types: ~B~, +- The ~not~ operator is only defined for boolean values (~B~). +- The ~-~ unary operator is defined for numeric basic types: ~B~, ~N~, ~Z~, ~R~, ~R^1~, ~R^2~, ~R^3~, ~R^1x1~, ~R^2x2~ and ~R^3x3~. It is not defined for ~string~ variables. -- pre and post increment operators, ~--~ and ~++~, are defined for all +- Pre and post increment operators, ~--~ and ~++~, are defined for all scalar basic types: ~N~, ~Z~ and ~R~. They are not defined for ~B~, ~R^1~, ~R^2~, ~R^3~, ~R^1x1~, ~R^2x2~, ~R^3x3~ and ~string~ variables. @@ -1309,7 +1311,22 @@ produces the compilation error Again, this is done to simplify the syntax and to avoid weird constructions. -**** TODO Binary operators +- Access operators are only defined for small vectors ~R^d~ and small + matrices ~R^dxd~. To avoid use of uninitialized variables (or + partially uninitialized variables), these are ~read-only~ access + operators. Their syntax is the following. +#+NAME: Rd-Rdxd-access-operator +#+BEGIN_SRC pugs :exports both :results output + let x:R^2, x = (1,2); + let A:R^3x3, A = (1,2,3,4,5,6,7,8,9); + + cout << "x[0] = " << x[0] << "\nx[1] = " << x[1] << "\n"; + cout << "A[0,0] = " << A[0,0] << "\nA[2,1] = " << A[2,1] << "\n"; +#+END_SRC +This code produces +#+results: Rd-Rdxd-access-operator + +**** Binary operators Syntax for binary operators follows again a classical structure if ~exp1~ and ~exp2~ denotes two expressions and if ~op~ denotes a binary