4 ms·
Or (inc clojure) perhaps? Isn't (++) an abomination in functional programming with immutable state?
by djacobs 16y ago
Or (inc clojure) perhaps? Isn't (++) an abomination in functional programming with immutable state?
- adbge 16y ago++ isn't defined in Clojure, and in Haskell ++ is used to concatenate lists. Using (inc) isn't considered an abomination, though.
- lmkg 16y ago(swap! clojure inc) is acceptable and a more literal translation, although refactoring your code to use (inc clojure) is usually more idiomatic. See also, ADD 1 TO COBOL GIVING COBOL.
- silentbicycle 16y ago"(inc clojure)". which is probably really good marketing. (About e.g. "succ ml", I'm not sure.)
- djacobs 16y agoWell, I agree with you that isn't fantastic marketing. But neither is using a mutator function name to describe a talk on a functional language. Rich Hickey loves to rail against nonsensical constructs/concepts like @date.day = 3, and I'm guessing he is very against the (++) method, as well. (How can you tell one number to become another number?)
- silentbicycle 16y agoI haven't done anything with Clojure, though I'm curious and wondering if would be worth my while. I'm already familiar with languages covering similar territory (Erlang, other Lisp dialects), but I haven't done much with the JVM. Also, the lack of tail-call optimization in Clojure is off-putting to me, but it looks several good design trade-offs elsewhere would probably make up for it. (I was thinking of tattoos, PS.)
- djacobs 16y agoI did not get the tatoo reference, haha. As far as I understand, though, there is TCO in Clojure, right? You just have to be explicit and use (recur).
- silentbicycle 16y agoThat's not TCO, that's just an optimization for individual recursion. You might be able to use it for multiple forms under the same recur (like w/ "labels"), but it's very different when it applies to everything. With TCO, you can use a set of mutually-recursive functions - you can set up a FSM via tail calls, use CPS for backtracking (and many other things), a re-entrant virtual machine where each opcode is a tail call (rather than a giant switch/case or lots of gotos), etc. Being able to use function calls like "gotos with arguments" (but with local scopes, etc.) can make some constructs much easier to read, reason about, etc. I'm not that familiar with the implementation of the JVM, but AFAICT it's due to difficulties setting up tail calls efficiently in JVM bytecode.
- bitsai 16y agoYou can do optimized mutual-recursion in Clojure as well, using (trampoline). As with the optimized self-recursion using (recur), it's more work and not as nice as built-in TCO, but this is likely as good as it gets for now, given the current limitations of the JVM.
- nickik 16y agoRich is very mutch pro tail calls. Look at his talk at the JVM Language http://wiki.jvmlangsummit.com/What_the_JVM_needs http://wiki.jvmlangsummit.com/What_the_JVM_needs (the video is not online jet). As soon as the JVM supports it Clojure will support it. For me recur and trampoline are quite ok. I would want to miss on clojure because of TCO but I don't know what would be possible with TCO. I hope I can learn that in one of the books I have here :)