Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pugs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
code
pugs
Commits
734299b6
Commit
734299b6
authored
2 years ago
by
Stéphane Del Pino
Browse files
Options
Downloads
Patches
Plain Diff
Update documentation wrt tuple -> variable/compound affectations
parent
217292e8
No related branches found
No related tags found
1 merge request
!164
Fix function with tuple type in codomain
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
doc/userdoc.org
+66
-0
66 additions, 0 deletions
doc/userdoc.org
with
66 additions
and
0 deletions
doc/userdoc.org
+
66
−
0
View file @
734299b6
...
...
@@ -1852,6 +1852,72 @@ The use case of tuples is to provide lists of data to the ~C++~
underlying methods. A classical example is to provide a set of
boundary conditions to a method.
**** Tuple and other variables
If one cannot access to specific values of tuple variables, one can
however dispatch their values to compound variable lists or to simple
variable. To do so the tuple content must be convertible to each of
the compound variable using the operator ~=~ rules (see the conversion
table in section [[implicit-conversion]]). The one to one matching is
checked at runtime.
#+NAME: tuple-to-compound
#+BEGIN_SRC pugs :exports both :results output
let t:(R), t = (1, 2, 3.4, -5);
let (x, y, u, A):R*R*R^1*R^1x1, (x, y, u, A) = t;
cout << "t = " << t << "\n";
cout << "x = " << x << "\n";
cout << "y = " << y << "\n";
cout << "u = " << u << "\n";
cout << "A = " << A << "\n";
#+END_SRC
This code gives
#+results: tuple-to-compound
#+BEGIN_note
One could have separate the declarations of ~x~, ~y~, ~u~ and ~A~ from the
affectation. Writing simply at some point
#+BEGIN_SRC pugs :exports code
(x, y, u, A) = t;
#+END_SRC
#+END_note
If the tuple contains only one entry, one can assign its value to a
simple variable.
#+NAME: tuple-to-variable
#+BEGIN_SRC pugs :exports both :results output
let t:(R^3), t = [1, 2, 3];
let x:R^3, x = t;
cout << "t = " << t << "\n";
cout << "x = " << x << "\n";
#+END_SRC
One gets
#+results: tuple-to-variable
If the size of the tuple does not match the number of space defining
the compound type, one gets a runtime error. For instance
#+NAME: tuple-to-compound-wrong-size
#+BEGIN_SRC pugs-error :exports both :results output
let t:(Z), t = (1, 2);
let (a, b, c):R*R*R, (a, b, c) = t;
#+END_SRC
produces
#+results: tuple-to-compound-wrong-size
or
#+NAME: tuple-to-variable-wrong-size
#+BEGIN_SRC pugs-error :exports both :results output
let t:(Z), t = (1, 2);
let a:R, a = t;
#+END_SRC
which gives
#+results: tuple-to-variable-wrong-size
** Statements
The ~pugs~ language supports classical statements to control the data
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment