Open EvanKirshenbaum opened 5 months ago
It dawned on me last night that in order to really do dynamic binding, you need to have a form that doesn't introduce a new binding, but rather performs an assignment and then undoes the assignment on exit. I'd propose adding a keyword such as temporary
or dynamic
or existing
, to allow you to say
with existing x = x + 1 { ... }
This sets the visible x
, which may be global or otherwise visible to dynamic calls.
Thinking about it, my initial choice of temporary
is probably bad, because people will assume they can say temp
, which will be read as temperature
, violating the PLA. dynamic
is too esoteric, so I'd go with existing
.
An alternative would be to say that if you provide a type, it's a new declaration, and if you don't, it's rebinding (and then restoring) the original. That may be more consistent with the rules for declarations and assignments. As with declarations, you can add local
if necessary to say "infer the type, but create a new variable".
It would be useful for macro writers to have an equivalent of
LET
(actually, probablyLET*
) expressions. Something likewith
x
andy
local to the block. I think that the least astonishing semantics is to have the variable declared sequentially (so that each can see the earlier value), allowing you to say things likewhen you're really only interested in the last one.
Also, as with current declarations, the initial value should be in the environment without the declaration, allowing you to do dynamic binding by saying
I think that, as with macros (https://github.com/HPInc/HP-Digital-Microfluidics/issues/160) [comment by @EvanKirshenbaum on Jan 20, 2023 at 3:19 PM PST], I probably want to allow both a statement form (taking a block) and an expression form, separating the header from the body by a colon.
Migrated from internal repository. Originally created by @EvanKirshenbaum on Feb 04, 2023 at 3:26 PM PST.