Skip to content
Snippets Groups Projects
Commit 83361fe2 authored by dgelessus's avatar dgelessus
Browse files

Allow spaces around equals sign in :let

parent 3fbe434b
Branches
Tags
No related merge requests found
%% Cell type:code id: tags:
``` prob
:help :let
```
%% Output
```
:let NAME EXPR
:let NAME=EXPR
```
Evaluate an expression and store it in a local variable.
The expression is evaluated once in the current state, and its value is stored. Once set, variables are available in all states. A variable created by `:let` shadows any identifier with the same name from the machine.
Variables created by `:let` are discarded when a new machine is loaded (or the current machine is reloaded). The `:unlet` command can also be used to manually remove local variables.
**Note:** The values of local variables are currently stored in text form. Values must have a syntactically valid text representation, and large values may cause performance issues.
:let NAME EXPR
:let NAME=EXPR
Evaluate an expression and store it in a local variable.
The expression is evaluated once in the current state, and its value is stored. Once set, variables are available in all states. A variable created by `:let` shadows any identifier with the same name from the machine.
Variables created by `:let` are discarded when a new machine is loaded (or the current machine is reloaded). The `:unlet` command can also be used to manually remove local variables.
**Note:** The values of local variables are currently stored in text form. Values must have a syntactically valid text representation, and large values may cause performance issues.
%% Cell type:code id: tags:
``` prob
:help :unlet
```
%% Output
```
:unlet NAME
```
Remove a local variable.
:unlet NAME
Remove a local variable.
%% Cell type:code id: tags:
``` prob
:let hello 1..5 \/ {10}
```
%% Output
$\{1,2,3,4,5,10\}$
{1,2,3,4,5,10}
%% Cell type:code id: tags:
``` prob
hello
```
%% Output
$\{1,2,3,4,5,10\}$
{1,2,3,4,5,10}
%% Cell type:code id: tags:
``` prob
:let n 2
```
%% Output
$2$
2
%% Cell type:code id: tags:
``` prob
n
```
%% Output
$2$
2
%% Cell type:code id: tags:
``` prob
{x | x : hello & x mod n = 0}
```
%% Output
$\{2,4,10\}$
{2,4,10}
%% Cell type:code id: tags:
``` prob
:unlet n
```
%% Cell type:code id: tags:
``` prob
n
```
%% Output
:eval: Computation not completed: Unknown identifier "n", did you mean "IN"?
%% Cell type:markdown id: tags:
Local variables can be used when setting a local variable.
%% Cell type:code id: tags:
``` prob
:let n 1
```
%% Output
$1$
1
%% Cell type:code id: tags:
``` prob
:let m n + 1
```
%% Output
$2$
2
%% Cell type:code id: tags:
``` prob
:let m m + 1
```
%% Output
$3$
3
%% Cell type:code id: tags:
``` prob
m
```
%% Output
$3$
3
%% Cell type:markdown id: tags:
Local variables are not persisted when a new machine is loaded.
%% Cell type:code id: tags:
``` prob
::load
MACHINE Empty
END
```
%% Output
Loaded machine: Empty
%% Cell type:code id: tags:
``` prob
hello
```
%% Output
:eval: Computation not completed: Unknown identifier "hello"
%% Cell type:markdown id: tags:
Local variables can be assigned with or without `=`.
%% Cell type:code id: tags:
``` prob
:let x 1
```
%% Output
$1$
1
%% Cell type:code id: tags:
``` prob
:let y=2
:let y = 2
```
%% Output
$2$
2
%% Cell type:code id: tags:
``` prob
:assert x + 1 = y
```
%% Output
$\mathit{TRUE}$
TRUE
%% Cell type:code id: tags:
``` prob
:let X {x | x : 0..10 & x mod 2 = 0}
```
%% Output
$\{0,2,4,6,8,10\}$
{0,2,4,6,8,10}
%% Cell type:code id: tags:
``` prob
:let Y={x | x : 0..10 & x mod 2 = 0}
```
%% Output
$\{0,2,4,6,8,10\}$
{0,2,4,6,8,10}
%% Cell type:code id: tags:
``` prob
X = Y
```
%% Output
$\mathit{TRUE}$
TRUE
%% Cell type:markdown id: tags:
Local variables can be used in Event-B mode.
%% Cell type:code id: tags:
``` prob
:language event_b
```
%% Output
Changed language for user input to Event-B (forced)
%% Cell type:code id: tags:
``` prob
1..5 \/ {10}
```
%% Output
$\{1,2,3,4,5,10\}$
{1,2,3,4,5,10}
%% Cell type:code id: tags:
``` prob
:let hello 1..5 \/ {10}
```
%% Output
$\{1,2,3,4,5,10\}$
{1,2,3,4,5,10}
%% Cell type:code id: tags:
``` prob
hello
```
%% Output
$\{1,2,3,4,5,10\}$
{1,2,3,4,5,10}
%% Cell type:code id: tags:
``` prob
hello = {}
```
%% Output
$\mathit{FALSE}$
FALSE
%% Cell type:code id: tags:
``` prob
hello /= {}
```
%% Output
$\mathit{TRUE}$
TRUE
%% Cell type:code id: tags:
``` prob
card(A) = 2 & hello /= A
```
%% Output
$\mathit{TRUE}$
**Solution:**
* $\mathit{A} = \{0,1\}$
TRUE
Solution:
A = {0,1}
......
......@@ -28,7 +28,7 @@ import org.jetbrains.annotations.NotNull;
public final class LetCommand implements Command {
private static final @NotNull Parameter.RequiredSingle NAME_AND_EXPRESSION = Parameter.requiredRemainder("nameAndExpression");
private static final @NotNull Pattern NAME_AND_EXPRESSION_SPLIT_PATTERN = Pattern.compile("=|\\s+");
private static final @NotNull Pattern NAME_AND_EXPRESSION_SPLIT_PATTERN = Pattern.compile("\\s*[\\s=]\\s*");
private final @NotNull Provider<@NotNull ProBKernel> kernelProvider;
private final @NotNull AnimationSelector animationSelector;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment