Skip to content

Understand multi‐values

cl4cnam edited this page Jan 22, 2024 · 8 revisions

In FuncSug, you don't work with values but with multi-values! What is that?

I'm going to explain that to you.
Each expression results in possibly multiple values. The set of these value(s) is named a multi-value.
Ditto for variables: They can hold multiple values. The set of these value(s) is the multi-value of the variable.

Enough with theory! Place to practice!

Zero value

I declare a variable:

var myVariable

At the moment just after the declaration, the variable myVariable doesn't contain any value! Yes, no value, NOT a null value, NOT an undefined value as in classical languages! The set of values of the variable is empty.

One value

Now, if I run:

myVariable := 34

Then, the variable contains exactly one value: 34. This case is exactly as in classical languages.

More than one value

For getting more than one value, I have to demand for multiple values! 😋 Here is the syntax: par(45, 23, 56). Yes, I demand for several values in parallel!

If I run:

myVariable := par(45, 23, 56)

Now, myVariable contains three values. The set of these three values is called a multi-value and is noted |45, 23, 56|.

dessin

Any number of value

Here are the syntaxes:

  • To get 0 value: par() or | | or an uninitialized variable
  • To get 1 value: par(34) or 34 or |34| (Yes, it's exactly the same!)
  • To get 2 or more values: par(45, 23, 56) or |45, 23, 56|

Important

I name multi-value the set of the whole content of a variable. That might be a N-value multi-value (N is 0, 1, 2 or more).

Tip

You can exercise with this console.

Operations with multi-values

With most operations, the operation is done with all possible combinations. For example, |100, 200| + |3, 4| gives |103, 104, 203, 204|. But there are exceptions: par(|100, 200|, |3, 4|) gives |100, 200, 3, 4| (It's just concatenation) and seq(|100, 200|, |3, 4|) gives |3, 4| (It's just the last argument).

Caution

Operations with | | can be very misleading! |3, 4| + | | gives | | (Note that it's really all the possible combinations).