"This external function takes a format string and a B sequence of values and generates an output string, where the values have been inserted into the format string in place of the `~w` placeholders.\n",
"This external function takes a format string and a B sequence of values and generates an output string, where the values have been inserted into the format string in place of the `~w` placeholders.\n",
" - the length of sequence must correspond to the number of \\verb+~w+ in the format string.\n",
" - the length of sequence must correspond to the number of `~w` in the format string.\n",
" - the format string follows the conventions of SICStus Prolog.\n",
" - the format string follows the conventions of SICStus Prolog.\n",
[2018-05-11 13:21:45,901, T+247729] "Shell-0" de.prob.cli.PortPattern.setValue(PortPattern.java:30): [INFO] Server has started and listens on port 62905
[2018-05-11 13:21:45,901, T+247729] "Shell-0" de.prob.cli.PortPattern.setValue(PortPattern.java:30): [INFO] Server has started and listens on port 62905
[2018-05-11 13:21:45,901, T+247729] "Shell-0" de.prob.cli.InterruptRefPattern.setValue(InterruptRefPattern.java:29): [INFO] Server can receive user interrupts via reference 40975
[2018-05-11 13:21:45,901, T+247729] "Shell-0" de.prob.cli.InterruptRefPattern.setValue(InterruptRefPattern.java:29): [INFO] Server can receive user interrupts via reference 40975
This external predicate takes a string and is true if the string represents an integer.
This external predicate takes a string and is true if the string represents an integer.
Type: $STRING $.
Type: $STRING $.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
STRING_IS_INT("1204")
STRING_IS_INT("1204")
```
```
%% Output
%% Output
TRUE
TRUE
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
STRING_IS_INT("-1204")
STRING_IS_INT("-1204")
```
```
%% Output
%% Output
TRUE
TRUE
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
STRING_IS_INT(" - 1204")
STRING_IS_INT(" - 1204")
```
```
%% Output
%% Output
TRUE
TRUE
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
STRING_IS_INT("1.1")
STRING_IS_INT("1.1")
```
```
%% Output
%% Output
FALSE
FALSE
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
STRING_IS_INT("1.0")
STRING_IS_INT("1.0")
```
```
%% Output
%% Output
FALSE
FALSE
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
STRING_IS_INT("a")
STRING_IS_INT("a")
```
```
%% Output
%% Output
FALSE
FALSE
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
STRING_IS_INT("1000000000000000000000000000")
STRING_IS_INT("1000000000000000000000000000")
```
```
%% Output
%% Output
TRUE
TRUE
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
STRING_IS_INT("-00001")
STRING_IS_INT("-00001")
```
```
%% Output
%% Output
TRUE
TRUE
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
STRING_IS_INT("00002")
STRING_IS_INT("00002")
```
```
%% Output
%% Output
TRUE
TRUE
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### STRING_TO_INT
### STRING_TO_INT
This external function takes a string and converts it into an integer.
This external function takes a string and converts it into an integer.
An error is raised if this cannot be done.
An error is raised if this cannot be done.
It is safer to first check with `STRING_IS_INT` whether the conversion can be done.
It is safer to first check with `STRING_IS_INT` whether the conversion can be done.
Type: $STRING \rightarrow INTEGER$.
Type: $STRING \rightarrow INTEGER$.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
STRING_TO_INT("1024")
STRING_TO_INT("1024")
```
```
%% Output
%% Output
1024
1024
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
STRING_TO_INT(" - 00001")
STRING_TO_INT(" - 00001")
```
```
%% Output
%% Output
−1
−1
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### INT_TO_STRING
### INT_TO_STRING
This external function converts an integer to a string representation.
This external function converts an integer to a string representation.
Type: $INTEGER \rightarrow STRING $.
Type: $INTEGER \rightarrow STRING $.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
INT_TO_STRING(1024)
INT_TO_STRING(1024)
```
```
%% Output
%% Output
"1024"
"1024"
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
INT_TO_STRING(-1024)
INT_TO_STRING(-1024)
```
```
%% Output
%% Output
"-1024"
"-1024"
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
INT_TO_STRING(STRING_TO_INT(" - 00001"))
INT_TO_STRING(STRING_TO_INT(" - 00001"))
```
```
%% Output
%% Output
"-1"
"-1"
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
STRING_TO_INT(INT_TO_STRING(-1))=-1
STRING_TO_INT(INT_TO_STRING(-1))=-1
```
```
%% Output
%% Output
TRUE
TRUE
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### DEC_STRING_TO_INT
### DEC_STRING_TO_INT
This external function takes a decimal string (with optional decimal places) and converts it to an integer with the given precision (rounding if required).
This external function takes a decimal string (with optional decimal places) and converts it to an integer with the given precision (rounding if required).
This external function converts a B data value to a string representation.
This external function converts a B data value to a string representation.
Type: $\tau \rightarrow STRING$.
Type: $\tau \rightarrow STRING$.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
TO_STRING(1024)
TO_STRING(1024)
```
```
%% Output
%% Output
"1024"
"1024"
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
TO_STRING("1024")
TO_STRING("1024")
```
```
%% Output
%% Output
"1024"
"1024"
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
TO_STRING({2,3,5})
TO_STRING({2,3,5})
```
```
%% Output
%% Output
"{2,3,5}"
"{2,3,5}"
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
TO_STRING((TRUE,3,{11|->rec(a:22,b:33)}))
TO_STRING((TRUE,3,{11|->rec(a:22,b:33)}))
```
```
%% Output
%% Output
"((TRUE|->3)|->{(11|->rec(a:22,b:33))})"
"((TRUE|->3)|->{(11|->rec(a:22,b:33))})"
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### FORMAT_TO_STRING
### FORMAT_TO_STRING
This external function takes a format string and a B sequence of values and generates an output string, where the values have been inserted into the format string in place of the `~w` placeholders.
This external function takes a format string and a B sequence of values and generates an output string, where the values have been inserted into the format string in place of the `~w` placeholders.
- the length of sequence must correspond to the number of \verb+~w+ in the format string.
- the length of sequence must correspond to the number of `~w` in the format string.
- the format string follows the conventions of SICStus Prolog.
- the format string follows the conventions of SICStus Prolog.
E.g., one can use \verb+~n+ for newlines.
E.g., one can use `~n` for newlines.
Type: $(STRING*seq(\tau)) \rightarrow STRING$.
Type: $(STRING*seq(\tau)) \rightarrow STRING$.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
FORMAT_TO_STRING("two to the power ten = ~w",[2**10])
FORMAT_TO_STRING("two to the power ten = ~w",[2**10])
```
```
%% Output
%% Output
"two to the power ten = 1024"
"two to the power ten = 1024"
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
FORMAT_TO_STRING("My two sets are ~w and ~w",[1..2,2..1])
FORMAT_TO_STRING("My two sets are ~w and ~w",[1..2,2..1])
```
```
%% Output
%% Output
"My two sets are {1,2} and {}"
"My two sets are {1,2} and {}"
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
#### Format Strings
#### Format Strings
Various external functions and predicates work with format strings.
Various external functions and predicates work with format strings.
ProB uses the conventions of the SICStus Prolog format string.
ProB uses the conventions of the SICStus Prolog format string.
-`~n` inserts a newline into the generated output
-`~n` inserts a newline into the generated output
-`~Nn` where N is a number: it inserts $N$ newlines into the output
-`~Nn` where N is a number: it inserts $N$ newlines into the output
-`~w` inserts the next argument into the generated output
-`~w` inserts the next argument into the generated output
-`~i` consumes the next argument but ignores it; i.e., nothing is inserted into the output
-`~i` consumes the next argument but ignores it; i.e., nothing is inserted into the output
-`~~` inserts the tilde symbol into the generated output
-`~~` inserts the tilde symbol into the generated output
-`~N` inserts a newline if not at the beginning of the line
-`~N` inserts a newline if not at the beginning of the line
SICStus Prolog also uses a few other formatting codes, such as `~@`, `~p`,... which should not be used.
SICStus Prolog also uses a few other formatting codes, such as `~@`, `~p`,... which should not be used.
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## Choose Operator
## Choose Operator
You can obtain access to the definitions below by putting the following into your DEFINITIONS clause:
You can obtain access to the definitions below by putting the following into your DEFINITIONS clause:
`DEFINITIONS "Choose.def"`
`DEFINITIONS "Choose.def"`
### Choose
### Choose
This external function takes a set and returns an element of the set.
This external function takes a set and returns an element of the set.
This is a proper mathematical function, i.e., it will always return the same value
This is a proper mathematical function, i.e., it will always return the same value
given the same argument.
given the same argument.
It is also known as Hilbert's operator.
It is also known as Hilbert's operator.
The operator raises an error when it is called with an empty set.
The operator raises an error when it is called with an empty set.
Also, it is not guaranteed to work for infinite sets.
Also, it is not guaranteed to work for infinite sets.
[2018-05-11 14:32:17,803, T+4479631] "Shell-0" de.prob.cli.PortPattern.setValue(PortPattern.java:30): [INFO] Server has started and listens on port 51046
[2018-05-11 14:32:17,803, T+4479631] "Shell-0" de.prob.cli.PortPattern.setValue(PortPattern.java:30): [INFO] Server has started and listens on port 51046
[2018-05-11 14:32:17,804, T+4479632] "Shell-0" de.prob.cli.InterruptRefPattern.setValue(InterruptRefPattern.java:29): [INFO] Server can receive user interrupts via reference 42415
[2018-05-11 14:32:17,804, T+4479632] "Shell-0" de.prob.cli.InterruptRefPattern.setValue(InterruptRefPattern.java:29): [INFO] Server can receive user interrupts via reference 42415