-
-
Notifications
You must be signed in to change notification settings - Fork 40
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
Starting the document on TLA+ idioms #325
Conversation
Shon, thanks for the comments! Co-authored-by: Shon Feder <shon@informal.systems>
Perhaps, the definition of --------------------------- MODULE BlockingQueueFair ---------------------------
...
VARIABLES buffer, waitSeq
vars == <<buffer, waitSeq>>
Range(f) == { f[i]: i \in DOMAIN f }
waitSet == Range(waitSeq)
RunningThreads == (Producers \cup Consumers) \ waitSet
NotifyOther(t) ==
LET S == IF t \in Producers THEN waitSet \ Producers ELSE waitSet \ Consumers
R == SelectSeq(waitSeq, LAMBDA u:u \in S)
T == SelectSeq(waitSeq, LAMBDA u:u \notin S)
IN IF R # <<>>
THEN waitSeq' = Tail(R) \o T
ELSE UNCHANGED waitSeq
(* @see java.lang.Object#wait *)
Wait(t) == /\ waitSeq' = Append(waitSeq, t)
/\ UNCHANGED <<buffer>>
-----------------------------------------------------------------------------
Put(t, d) ==
\/ /\ Len(buffer) < BufCapacity
/\ buffer' = Append(buffer, d)
/\ NotifyOther(t)
\/ /\ Len(buffer) = BufCapacity
/\ Wait(t)
Get(t) ==
\/ /\ buffer # <<>>
/\ buffer' = Tail(buffer)
/\ NotifyOther(t)
\/ /\ buffer = <<>>
/\ Wait(t)
...
============================================================================= In contrast, this is the variant with one more variable that separates |
Nice example, @lemmy. It indeed looks cleaner with one more variable. By the way, I am also violating this rule from time to time :-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool!
I initially wanted to ask if this repo is the right place to collect the idioms (VDD might have been better), but I understand that some idioms are actually Apalache-specific.
Yes! That sounds good! Co-authored-by: Shon Feder <shon@informal.systems>
Co-authored-by: Adi Seredinschi <adi@informal.systems>
Co-authored-by: Adi Seredinschi <adi@informal.systems>
Co-authored-by: Adi Seredinschi <adi@informal.systems>
I will merge this PR so it becomes more visible. Feel free to propose changes. |
Perhaps, auxiliary (history/prophecy) variables deserve mention too. |
This document has been living in a separate branch for several months. Let's start writing it. The first two idioms are in.