Open TyOverby opened 9 years ago
hrmmmm well, to be totally honest, I think both of these things ought to be implemented within ares as macros (except we don't have macros yet, so that opinion is somewhat moot). Your switch
is similar to Clojure's condp
, but different enough that reusing the name might be confusing---otherwise I think it would be perfect.
I think they should ideologically should be macros, but because they would be included in #28 I'm wary.
I never was a fan of condp, but condp seems a lot more "switch-like" than our "switch" because the cases are values.
I'd rename it to "match", but because this is rust, I don't want there to be any pattern-matching confusion.
Maybe a name that no one uses and is vague enough to make sense? "branch?"
Right, the switch you're proposing can be recreated with Clojure's condp
as
(condp #(%1 %2) value function1 result1 function2 result2 ...)
I personally find the switch
semantics a better fit with the name condp
. branch
seems good (or possibly branchp
to emphasize that the arms are predicates).
I've renamed switch
to condp
.
Adds two new
user_fn
based macros to the core stdlib.Cond is your typical "evaluate left, if that was true, result is eval right".
Switch takes a value and evaluates left as a function with the argument being the value. If the result of that is true, result is eval of right.
I really like
switch
but I'm not sure it should be named that. @bwo: what are your thoughts?Also, I think I forgot to push my most recent changes on this branch; I'll do that when I get home.