6 ms·
Common Lisp has the advantage of being much more stable in terms of language changes. You can pretty much take CL code from the last two decades and run it. It'
by justinhj 8y ago
Common Lisp has the advantage of being much more stable in terms of language changes. You can pretty much take CL code from the last two decades and run it. It's also got a better native compilation story.
I like Clojure for bringing maps and vectors into first class language constructs with simple syntax and the fact that it runs on the JVM means I have access to the entire Java ecosystem of libraries and tools.
- lispm 8y agoI wonder where the vector myth comes from. Common Lisp always had a vector data type and syntax for it. Just not [], but #(). Actually Common Lisp has multi-dimensional arrays, bitvectors, ... Vector: CL-USER 102 > (map 'vector #'char-code "foobar") #(102 111 111 98 97 114) CL-USER 103 > (reduce #'+ #(102 111 111 98 97 114)) 633 Bitvector: CL-USER 105 > (reduce #'+ #*10101001010101) 7 2d-Array CL-USER 106 > (aref #2a((1 2) (3 4)) 1 1) 4
- justinhj 8y agoI didn't say CL has no vectors or syntax, just that in Clojure using sets, maps and vectors, is much more similar to using lists than it is in CL.
- lispm 8y agoCommon Lisp reads and writes vectors, has a simple syntax for them and provides a sequence abstraction over lists and vectors.
- justinhj 8y agoOperations that in Clojure require only changing the kind of brackets, in Common Lisp are more verbose and explicit. If you don’t see the clean syntax and simple utility in that then fair enough, but I do.
- lispm 8y agoreading and reducing a list: CL-USER 109 > (reduce #'+ (read)) (1 2 3) 6 reading and reducing a vector: CL-USER 110 > (reduce #'+ (read)) #(1 2 3) 6 I've changed only the opening bracket.
- justinhj 8y agoDid you change from map to reduce because map needs to be told what kind of sequence to create? In Clojure the literal syntax avoids that. In addition there is this caveat about the literal vector syntax in Common Lisp: You can use the #(...) syntax to include literal vectors in your code, but as the effects of modifying literal objects aren't defined, you should always use VECTOR or the more general function MAKE-ARRAY to create vectors you plan to modify.
- lispm 8y agoThe literal syntax has nothing to do with MAP. I can define a MAP which returns a vector or a list, depending on the input: CL-USER 111 > (defun maps (function sequence) (map (type-of sequence) function sequence)) MAPS CL-USER 112 > (maps #'1+ '(1 2 3)) (2 3 4) CL-USER 113 > (maps #'1+ #(1 2 3)) #(2 3 4) I can also write a compiler macro, so that the implementation is chosen at compile time, when a literal data object is used... stuff which a Common Lisp implementation already might do for MAP. Common Lisp chose to define the basic MAP to always specify the result sequence I want to create or NIL for no sequence. > You can use the #(...) syntax to include literal vectors in your code, but as the effects of modifying literal objects aren't defined, you should always use VECTOR or the more general function MAKE-ARRAY to create vectors you plan to modify. That's not different for lists and vectors. For both I need to know which I want to modify. Common Lisp has generic operations to create and copy sequences for that: I can call COPY-SEQ to copy the literal sequence or call MAKE-SEQUENCE to create the sequence type I want. Here (and in many other places) Common Lisp is a low-level language, which exposes these things to the programmer.
- justinhj 8y ago
- justinhj 8y agoI guess I should also mention on Clojure's side, the immutable by default data model and pattern matching.
- deleted 8y ago[deleted]