3 ms·
A fair amount of the examples involve mutation; a practice that Clojure discourages. A lot of the macros are very instructive, however.
by chongli 13y ago
A fair amount of the examples involve mutation; a practice that Clojure discourages. A lot of the macros are very instructive, however.
- brudgers 13y agoIndeed, On Lisp has an excellent discussion of mutation and its use in programs written in a functional style. In discussing destructive functions, Graham describes the ways in which they can be used with reasonable safety - e.g. immediately mutating a list newly created by a mapping function. The reasons one might do so in Clojure are likely to bear similarity to those provided by Graham - speed and memory - despite the vastly greater resources of today's computers versus those of 1991.
- chongli 13y agoVery good point. Mutation is extremely useful when birthing a new data structure; this is a time when it's not yet visible to the rest of the system so the danger of sharing intermediate state does not occur. Clojure has a very elegant facility for dealing with this particular scenario: http://clojure.org/transients http://clojure.org/transients