27 ms·
There is no conditional, and without a conditional you can't get a conditional. However modifying it to support conditionals is easy. Just add a built-in func
by btilly 15y ago
There is no conditional, and without a conditional you can't get a conditional.
However modifying it to support conditionals is easy. Just add a built-in function if(condition, expr1, expr2). Now you can build if's. Since the language already properly supports recursive function calls, now it is possible to implement loops through recursion, and you're off and running.
- tmhedberg 15y agoIf you have function application, then you don't truly need a primitive conditional. You can represent Boolean values and conditional functions with the Church encoding [1]. This is how conditionals are represented in, for instance, the lambda calculus. [1] http://en.wikipedia.org/wiki/Church_encoding#Church_booleans http://en.wikipedia.org/wiki/Church_encoding#Church_booleans
- btilly 15y agoGood point. But you need to have first class functions for that. This toy language does not. And converting from "this native number equals that native number" to your encoding of "true" is going to be an interesting trick.
- yossi_peti 15y agoThere is a slight snag that arguments to a function are eagerly evaluated. A built-in if function would be more useful as a special form.
- anamax 15y ago> There is no conditional, and without a conditional you can't get a conditional. A two element array of function pointers (or code addresses) and an operator that turns true/false into 0/1 is enough to do conditionals.