Hacker News new | past | comments | ask | show | jobs | submit login

Well, it's actually impossible to write if as a function in Clojure.



I think it's impossible to write if as a function in anything, I'm pretty sure that at some point you need a branching primitive, but the if the VM uses and the if exposed to the user don't have to be the same thing. Like I said though, it's not a Clojure specific question, CL and Scheme both use a special form for if as well. Even if it can't be done in a JVM language it can be done. I'm just curious if there's any particular reason it isn't done, like being way easier for a compiler/interpreter to optimize or something or if it's mostly historical.


The first problem you run into is call by value. As a function the args to if would be evaluated before the function call. You could force the user to quote the branches to the if call to get around it but the special form is less error prone.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: