Open tekknolagi opened 10 months ago
TODO: add some EvalTests
Would the question mark operator work here?
id 2
. id =
| x ? x==1 -> "one"
| x -> "idk"
Yes, although I think it is already being used for what I originally understood as an assert. We can repurpose as guard (which won't raise/crash). Or we can rename to if
.
I'm a liiiiittle wary of having a bunch of symbols
Yeah, ?
is an assert, that's why I think it fits kind of naturally there.
Regarding symbols, one of my design goals of scrapscript is to actually have no alphabetic keywords in the whole language! I don't know why this was a goal of mine, but I think it's a constraint that's encouraged "small" thinking.
I think if we drop its meaning as assert and instead use it to mean guard (and fall-through on guard failure, instead of crash), sure, why not
Then it's possible to write assert = | # true -> ()
which will raise/fail due to lack of matches
Love it! Great idea
Adds guards to pattern matching:
Where guards run in a merged version of the match case env and the env created by the pattern matching.