Skip to content
Snippets Groups Projects
Commit 54db8b5b authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Add doc for access operator

parent 27ebe0ac
No related branches found
No related tags found
1 merge request!145git subrepo clone git@gitlab.com:OlMon/org-themes.git packages/org-themes
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment