-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request: Add string formatting operator #85
Comments
Also, TLA+ doesn't allow indexing strings to check if it starts and ends with |
Strings are sequences in TLA+. Do any of the operators below help with your use case? CommunityModules/modules/SequencesExt.tla Lines 366 to 432 in 626a6bd
By the way, does the TLA+ debugger (VSCode) address your underlying debugging need? |
They don't, unfortunately. TLC isn't treating strings as sequences here: \* ToString, PrintT from TLC module
\* Head from Sequences module
\* flatten and Last from SequencesExt module
Str(s) ==
LET Result == ToString(s)
IN IF Head(Result) = "\"" /\ Last(Result) = "\""
THEN s
ELSE Result
Format(seq) ==
IF Len(seq) = 0 THEN seq
ELSE
LET flatten[i \in 1..Len(seq)] ==
IF i = 1
THEN Str(seq[i])
ELSE flatten[i-1] \o Str(seq[i])
IN flatten[Len(seq)]
...
ASSUME PrintT(Format(<<"Hello", 2>>)) It's interesting that the The example above generated the error: Also, this doesn't work either: Str(s) ==
IF s \notin STRING
THEN ToString(s)
ELSE s Generates Although I'm not so sure about the latter
It did! :) |
You've discovered a shortcoming of TLC, not of TLA+: TLC does not have characters, which is why, e.g., |
Given than many operators in the CommunityModules are overriden by Java implementations, would it be possible or, rather, useful to have a Format operator (or anything of the sort) anyway, since one can't be specified in TLA+? |
What would the definition of |
My TLA+ definition of
The first one reminds me of a few dynamically typed languages. It's easier to read and harder to implement. Also, it's depends on some arbitrary placeholder. In this case, "{}". The second one is a little harder to read, but it only depends on string conversion and concatenation. |
Let's just expose Java's It is also consistent with: CommunityModules/modules/CSV.tla Lines 9 to 14 in 626a6bd
|
So I assume the placeholders would be |
Perfect. I get it now. Thanks, Markus |
String formatting overloads would make debugging easier when used in conjunction with
PrintT()
. I'm aware VSCode has a LLVM debugger, but the Toolbox does not... There might be other uses of which I'm not aware.For example, we could have a
TLCExt!Format(sequence)
operator that converts any non-string element of a sequence to string and concatenates all of them. That might be possible in TLA⁺, but slow because the language lacks typing.Any thoughts?
The text was updated successfully, but these errors were encountered: