How to generate a sequence from another sequence ?

176 views
Skip to first unread message

Ashish Negi

unread,
Nov 11, 2020, 12:03:31 AM11/11/20
to tlaplus
Hi

I have a sequence of records with field `id`. I want to get a sequence of all ids from original sequence.

My first attempt was to try this :
[r \in some_sequence_of_records |-> r.id]

"The exception was a java.lang.RuntimeException
: util.Assert$TLCRuntimeException: The domains of formal parameters must be enumerable.
The error occurred when TLC was evaluating the nested
expressions at the following positions:
    The error call stack is empty."

Q1. Is "some_sequence_of_records" a set with DOMAIN 1..Len(sequence) ?
Q2. What is wrong with my first try ?

Currently, i am using custom map and filter functions for the sequences.

RECURSIVE mapSeq(_,_,_)
mapSeq(seqs, M(_), result) ==
    IF seqs = <<>>
    THEN result
    ELSE mapSeq(Tail(seqs),
                   M,
                   Append(result, M(Head(seqs))))

GetAllIds(files) ==
    LET getId(r) == r.id
    IN mapSeq(files, getId, <<>>)

Q3. Is there a better way ?

Thanks
Ashish

Stephan Merz

unread,
Nov 11, 2020, 2:17:42 AM11/11/20
to tla...@googlegroups.com
As far as I can tell, your attempt failed because a sequence is a function whereas the construct [x \in S |-> ...] expects a set S. Why not simply

[i \in 1 .. Len(files) |-> files[i].id]

where `files' is your input sequence?

Stephan

--
You received this message because you are subscribed to the Google Groups "tlaplus" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tlaplus+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tlaplus/5f09aa29-391f-49f1-833f-c6200fa2450co%40googlegroups.com.

Ashish Negi

unread,
Nov 11, 2020, 5:26:45 PM11/11/20
to tlaplus
Thanks Stephan for providing alternate method.

Is sequence a set or primitive type ?
Stephan

To unsubscribe from this group and stop receiving emails from it, send an email to tla...@googlegroups.com.

Ashish Negi

unread,
Nov 11, 2020, 10:26:16 PM11/11/20
to tlaplus
Q. does `[i \in 1 .. Len(files) |-> files[i].id]` gives back a sequence ?

Q. Is there something like a REPL where i can try different statements of TLA+ to check the output ?


On Tuesday, 10 November 2020 23:17:42 UTC-8, Stephan Merz wrote:
Stephan

To unsubscribe from this group and stop receiving emails from it, send an email to tla...@googlegroups.com.

Stephan Merz

unread,
Nov 12, 2020, 2:27:22 AM11/12/20
to tla...@googlegroups.com

On 12 Nov 2020, at 04:26, Ashish Negi <thisismy...@gmail.com> wrote:

Q. does `[i \in 1 .. Len(files) |-> files[i].id]` gives back a sequence ?

Yes: in TLA+ a sequence is a function with domain 1..n, for some n \in Nat.


Q. Is there something like a REPL where i can try different statements of TLA+ to check the output ?

You can use TLC to evaluate constant expressions.

Is sequence a set or primitive type ?

Semantically, all TLA+ values are sets, but there are many values for which it is not specified which sets represent them. These include numbers and functions, and therefore also sequences and records. It is more useful to think of these classes of values as being primitive.

Stephan

To unsubscribe from this group and stop receiving emails from it, send an email to tlaplus+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tlaplus/a956a38f-2ecf-4066-b0a7-167a69d400cco%40googlegroups.com.

Willy Schultz

unread,
Nov 16, 2020, 9:09:01 AM11/16/20
to tlaplus
Note that the latest versions of TLC also include a simple built-in REPL for evaluating TLA+ expressions. You can run it with:

java -cp tla2tools.jar tlc2.REPL

You can see a demo here and you can download the latest (nightly) build of the TLC tools from here: https://nightly.tlapl.us/dist/tla2tools.jar.

Will

Reply all
Reply to author
Forward
0 new messages