15 ms·
Which one is obscure ? define factorial (lambda (n) (if (= n 0) 1 (* n (factorial (- n 1)))))) let rec fact = function | 0 -> 1 | n -> n * fact (n - 1
by webreac 13y ago
Which one is obscure ?
define factorial
(lambda (n)
(if (= n 0) 1
(* n (factorial (- n 1))))))
let rec fact = function
| 0 -> 1
| n -> n * fact (n - 1);;
There is a little more syntax to learn in caml, but the suppression of 90% of the parenthesis makes the code far easier to read.
- gnosis 13y agoWith syntax hilighting and proper indenting, the Scheme code is pretty easy to read: http://img1.imagilive.com/0413/scheme-fact.png http://img1.imagilive.com/0413/scheme-fact.png You could even simplify it a little by getting rid of the lambda: http://img1.imagilive.com/0413/scheme-fact2.png http://img1.imagilive.com/0413/scheme-fact2.png In any case, I find toy examples like this less than convincing. In real-world programs, issues of style, design, and documentation usually trump most anything else, as far as clarity is concerned. Also, I personally find the penchant for one-letter variable names in the OCaml/SML/Haskell world to be very confusing and obfuscating. The Scheme way is to be more verbose and explicit. For me, that results in much greater clarity -- especially when looking at unfamiliar code or code that you've stepped away from for a few months. Of course, there also such a thing as being too verbose and explicit. But for me, Scheme is in the sweet spot between verbosity and terseness.
- davexunit 13y agoI find the lisp easier to read.
- eru 13y agoE.g. Haskell has enough syntactic sugar for some an even simpler version factorial n = product [1..n]