Notes from a newbie after doing the kettle tutorial #435
Replies: 7 comments 7 replies
-
The
under the assumption that this alternative formulation without the prime would be confusing:
I think we can say that it is strictly necessary any time you are specifying the value of a state variable in the next state, which is the case for all "assignments" :) WDYT? Any ideas on how we could make this clearer? |
Beta Was this translation helpful? Give feedback.
-
State variables refer to regions of state. This is a fundamental concept that takes a bit of time to grasp. But one way to think of this is that, in the context of the simulator, state variables are ref cells. Or, equivalently, the value of a state variable is a function of the current state. As you change the state (by applying actions) their value will change. So Perhaps an aside or a link in the REPL tutorial to the basic concepts for state variables would be useful? |
Beta Was this translation helpful? Give feedback.
-
There's been some prior discussion on separating out preconditions from "updates" and in general on exploring alternative syntax for actions. See #207 if you're interested in giving input on any of the ideas we've been kicking around :)
This is because I think this point touches on a key conceptual shift that differs from the usual programming languages, which I've tried to elaborate a bit here #372 (comment) No obligation, but I'd be interested to know if any of this helps clarify, or if we are still missing the mark when it comes to explaining the shift in thinking on this point. |
Beta Was this translation helpful? Give feedback.
-
This is a great point and connects with an ongoing debate over |
Beta Was this translation helpful? Give feedback.
-
This is a good point. I've tried to making a fitting change in #436 |
Beta Was this translation helpful? Give feedback.
-
In general, we have in mind a mechanism for this, but there is some subtlety and I think the discussion is not totally settled.
Did you try
Please let know if I'm missing the point here! |
Beta Was this translation helpful? Give feedback.
-
Thank you for the helpful responses @shonfeder! I'll aggregate my current understanding & suggestions in this one comment here. It seems like conveying the "state machine" + "delayed assignment" semantics is a core issue. I think I understand the issue at hand here, and I still don't see why it couldn't completely be modeled in the "traditional imperative syntax". Here's how I would design the syntax; hopefully this is helpful input into the whole syntax discussions, or at least would just shed light on what I'm still confused about. I would have a TNT "module" be similar to a Java class. By that I mean that "global variables in the file" are implicitly defined as state variables, and methods in the file are your actions. That is, actions map from state to state, and methods can do just that. Preconditions are
With this syntax, we still get the "normal assignments", and I don't think there would be any confusion as to whether I'm using the "pre-state" or "post-state" of a variable, as discussed here. An alternative "API" would be to have methods return " Now I don't have the whole context/experience of writing specs to know if this is actually a good idea, but hopefully this take on solving a few problems I've experienced can help in any way. |
Beta Was this translation helpful? Give feedback.
-
I thought I'd share my notes when taking the tutorial here; hopefully it can be useful for you to see what goes on in the mind of a newbie :).
Why is the
'
necessary when assigning a var?'
syntax when that is strictly necessary? I'll let you be the judge of that!Sections 5.2 & 5.3 were surprising to me:
kettleState
uses reference semantics; the syntax for me suggested value semantics (i.e. copying).val kettleState = { heatingOn: heatingOn, beeping: beeping, temperature: temperature }
creates references to variables, as opposed to copying their state.The
all {}
expression used in actions combines pre-conditions, as well as "assignment statements" (which I assume evaluate to true).bool
(as opposed to, say, the value that was assigned, as in C).I tried
4.1. Why do I need to specify how every variable changes? Would it be bad if TNT assumed that any unspecified change means "no change"?
4.2.
heatingOn
andbeeping
are unusable after this statement.with no way to assign a new value to it.
About
nondet temp = oneOf(-40.to(40))
. Puttingnondet
before the variable name is confusing to me.oneOf
being non-deterministic, andtemp
to simply be anint
that gets assigned the result of evaluatingoneOf
.At the end of "5.5. Introducing data non-determinism", the explanation for the snippet
is:
I initially read this as "the
nondet
syntax is a REPL-only feature". After re-reading the whole explanation, I realized that REPL here meant "the whole interpreter as used by the REPL program". In other words, for me, REPL means literally the "read-eval-print loop"; the program that reads user input, manages the history of commands, etc. Could this be reworded as:General feedback
All in all, I agree with Ethan that this was delightful 😉. With no prior background, I was able to follow easily and get a feel for TNT. The feel of the REPL was also great; reminded me of
ipython
!Beta Was this translation helpful? Give feedback.
All reactions