From 54db8b5b8fedfd3781d3500d2cd438f771c13457 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Del=20Pino?= <stephane.delpino44@gmail.com>
Date: Tue, 24 May 2022 16:49:56 +0200
Subject: [PATCH] Add doc for access operator

---
 doc/userdoc.org | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/doc/userdoc.org b/doc/userdoc.org
index 1eaa03f39..207e283d6 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
-- 
GitLab