Open crb233 opened 1 year ago
I think it'd be nice to have output without input as that wouldn't require modifying the state. I have a similar argument against the coin flip operation. I am in favor of the output builtin just printing out the current input as a number and otherwise acting as the identity. I quite like the property A { B | C }
= { A B | A C }
, I think it makes the language feel cleaner.
Even !
breaks this property, in a weaker sense. It doesn't affect the program execution, but it does affect what the user sees. ! { - | + }
always prints exactly once, but { ! - | ! + }
may print twice.
I feel like since it doesn't effect internal state it's more in line with the language's design philosophy.
regarding ?
, I think the best way to handle that might be to allow specifying a starting number for the program. That way input is always given exactly once. (no input being given could be equivelant to 0 being given.)
It would be nice to have I/O built-ins
?
and!
added to the official specification (no longer just for debugging). Another useful built-in would be a 'coin flip'%
which fails with probability 1/2 and acts like the identity function otherwise. However, these stateful operations don't seem to play well with Unarian.The language currently has a nice property where
A { B | C }
is semantically equivalent to{ A B | A C }
(although an analogous property doesn't hold:{ A | B } C
is not the same as{ A C | B C }
). So I would want? { - | + }
to be equivalent to{ ? - | ? + }
. However, the naive implementation of?
which asks for new input every time it's encountered can break this property, since the second expression sometimes asks for input twice. The alternative is to store a buffer of inputs so that every nth call to?
produces the same result. Unfortunately, solving the same problem for!
creates a new problem where we can't print out anything until the program exits (since we could be on a failing execution path and will overwrite previously printed values with new ones). This is obviously undesirable if we want to print as we go or run programs that might never terminate.At the moment, I'm leaning toward throwing out the property
A { B | C }
={ A B | A C }
in favor of having simple stateful operations.