TyOverby / ares

A Lisp made for easy integration with Rust.
9 stars 1 forks source link

Add cond and condp #30

Open TyOverby opened 9 years ago

TyOverby commented 9 years ago

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.

bwo commented 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.

TyOverby commented 9 years ago

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?"

bwo commented 9 years ago

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).

TyOverby commented 8 years ago

I've renamed switch to condp.