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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
code
pugs
Commits
79651a8d
Commit
79651a8d
authored
May 25, 2022
by
Stéphane Del Pino
Browse files
Options
Downloads
Patches
Plain Diff
Add documentation for tuples (+minor fixes)
parent
b607292b
No related branches found
No related tags found
1 merge request
!145
git subrepo clone git@gitlab.com:OlMon/org-themes.git packages/org-themes
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
doc/userdoc.org
+83
-3
83 additions, 3 deletions
doc/userdoc.org
with
83 additions
and
3 deletions
doc/userdoc.org
+
83
−
3
View file @
79651a8d
...
@@ -727,11 +727,12 @@ In order to avoid ambiguities, in ~pugs~, there is *no implicit*
...
@@ -727,11 +727,12 @@ In order to avoid ambiguities, in ~pugs~, there is *no implicit*
conversion in general.
conversion in general.
#+BEGIN_note
#+BEGIN_note
Actually, there are only t
wo
situations for which implicit type
Actually, there are only t
hree
situations for which implicit type
conversion can occur
conversion can occur
- when the value is given as a parameter of a function, or
- when the value is given as a parameter of a function, or
- when the value is used as the returned value of a function.
- when the value is used as the returned value of a function.
This will be detailed in section [[functions]].
- when the value is used to define a tuple
This will be detailed in section [[functions]] and [[tuples]]
#+END_note
#+END_note
This means that all affectation, unary and binary operators are
This means that all affectation, unary and binary operators are
...
@@ -1613,6 +1614,33 @@ types. This is transparent to the user and provides the intuitive
...
@@ -1613,6 +1614,33 @@ types. This is transparent to the user and provides the intuitive
(similar) behavior since data of high-level variables are constant. To
(similar) behavior since data of high-level variables are constant. To
illustrate this, let us consider the following example.
illustrate this, let us consider the following example.
#+BEGIN_SRC pugs :exports both
import mesh;
let m1:mesh, m1 = cartesian2dMesh(0, (1,1), (10,10));
let m2:mesh, m2 = m1;
let m3:mesh, m3 = cartesian2dMesh(0, (1,1), (10,10));
m3 = m1;
#+END_SRC
In this example, we are dealing with 3 ~mesh~ variables.
- First ~m1~ is defined as a uniform cartesian mesh in dimension 2 of
$]0,1[^2$ made of $10\times10$ identical square cells.
- Then ~m2~ is a copy of the variable ~m1~. It is a copy of the variable,
but the underlying mesh is *the same*! There is no duplication of the
mesh in memory.
- Then the mesh variable ~m3~ is *defined* to refer to a *new* mesh. It is
/similar/ to the mesh contained in ~m1~ and ~m2~, but it is *not* the same
one! When ~m3~ is defined two meshes, (and two connectivities) are
resident in memory. One of the mesh is referred by either ~m1~ or ~m2~
and the other one is referred by ~m3~.
- Finally, the last instruction (~m3 = m1;~) sets ~m3~ to also refer the
mesh referred by ~m1~ and ~m2~. Since no other variable refers to its
former mesh, it is destroyed (memory is freed). At the end of the
program, all the variables ~m1~, ~m2~ and ~m3~ are referring to the same
mesh, and there is only one mesh that resides in memory.
*** Compound types
*** Compound types
The ~pugs~ language allow to deal with compound types. The idea is to
The ~pugs~ language allow to deal with compound types. The idea is to
...
@@ -1638,6 +1666,12 @@ the output is
...
@@ -1638,6 +1666,12 @@ the output is
This is completely equivalent to declaring the variables one after the
This is completely equivalent to declaring the variables one after the
other.
other.
#+BEGIN_note
Observe that there is no implicit conversion when dealing with
compound types. The ~=~ operators are used sequentially to set the
different variables.
#+END_note
**** Compound definition
**** Compound definition
One can also use the following definition instruction
One can also use the following definition instruction
...
@@ -1708,7 +1742,53 @@ section [[functions]], functions can return compound values, thus compound
...
@@ -1708,7 +1742,53 @@ section [[functions]], functions can return compound values, thus compound
affectations (or definitions) are needed to get returned values in
affectations (or definitions) are needed to get returned values in
that case.
that case.
*** TODO Tuples types
*** TODO Tuple types<<tuples>>
The last special type construction is the ability to deal with tuples
in the ~pugs~ language. The tuples we are describing here are lists of
data of a *unique* and *simple* type (one cannot use compound types to
define tuples).
The list of values given to the tuple must be *implicitly* convertible
to the type of tuple elements. There is no ambiguity, the implicit
conversions follow the rules of operator ~=~.
**** Tuple declaration and affectation
For instance, one may write
#+NAME: tuple-declaration-affectation
#+BEGIN_SRC pugs :exports both :results output
let x:(R);
x = (1,2,3.4,2);
cout << x << "\n";
#+END_SRC
Executing this code, one gets
#+results: tuple-declaration-affectation
**** Tuple definition
The definition syntax is also possible.
#+NAME: tuple-definition
#+BEGIN_SRC pugs :exports both :results output
let x:(R^2), x = ((1,2),(3.4,2), 0, (2,3));
cout << x << "\n";
#+END_SRC
This code gives
#+results: tuple-definition
Observe that the special value ~0~ is used there.
**** Tuple purpose
Tuples variables are just lists of data of the same type. In the ~pugs~
language, one cannot access to a specific value of the list nor alter
one of them. This is not something that should ever change. Tuples are
not arrays! The ~pugs~ language is not meant to allow low-level
instructions.
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.
** TODO Statements
** TODO Statements
...
...
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