7 ms·
You also don't need to quote data structures other than the list in Clojure since they evaluate to themselves. (foo '(1 2 3)) simply becomes (foo [1 2 3])
by jeremiep 12y ago
You also don't need to quote data structures other than the list in Clojure since they evaluate to themselves.
(foo '(1 2 3)) simply becomes (foo [1 2 3])
- lispm 12y agoJust like Common Lisp and Scheme. Common Lisp: A vector: CL-USER 34 > #(1 2 3) #(1 2 3) A string: CL-USER 35 > "1 2 3" "1 2 3" A structure: CL-USER 36 > #S(FOO :A 1 :B 2 :C 3) #S(FOO :A 1 :B 2 :C 3)
- brudgers 12y agoWhat I appreciate from a design standpoint...i.e. aesthetically is the `defn` special form versus `defun` and `define`. In Common Lisp, `defun` takes on the general form of the lambda: lambda (x)(+ x 1) defun f (x)(+ x 1) Syntactically `(x)` looks like it should be evaluated, but isn't because there are special rules for special forms, and each special form can have it's own rules: let ((x 7)(y 3)) (+ x y) is a whole `nother set of syntactical rules which are even more in conflict with normal rules of evaluation. Scheme, keeps the let and uses a syntax for `define` that mimics the function call rather than the lambda. define (f x) (+ x 1) f 1 In Clojure the use of a vector for `defn` arguments follows it's formal lambda form like Common Lisp and is very much consistent with Clojure's rules for evaluation. fn [x] (+ x 1) defn f [x] (+ x 1) Likewise Clojure's `let` syntax does not require wetware parsing to recognize what gets evaluated and what doesn't. let [x 1 y 3] (+ x y) What I am appreciating about Clojure as a language is that it prunes some historic artifacts from the Lisp family tree. Raw memory allocation with `cons` made sense when human memory could retain more facts than a computer's fast memory. This meant it was easy to think of useful programs too big to fit in memory. That's distinctly harder today where doubling fast memory is less than $300 for the vast majority of computers. Lisp was developed as a direct improvement over assembly. Clojure was developed as a direct improvement over Java over C++ over C over assembly. It's a rethinking of what a Lisp needs (when backwards compatibility is ignored). It's an interesting design.
- lispm 12y agoLisp has a different design philosophy. Lisp prefers minial syntax for s-expressions and then Lisp syntax is defined on top of that. Learning what is evaluated or not is a part of that. Using array syntax for arglists is just arbitrary. Clojure is inconsistent anyway. (defmacro and ([] true) ([x] x) ([x & rest] `(let [and# ~x] (if and# (and ~@rest) and#)))) Can you explain why this has parentheses: ([x] x) ? Is that meant to be evaluated? > Likewise Clojure's `let` syntax does not require wetware parsing to recognize what gets evaluated and what doesn't. let [x 1 y 3] (+ x y) This is all inconsistent. A vector [x 1 y 3] is evaluated. But in LET 1 and 3 are evaluated. x and y not. > What I am appreciating about Clojure as a language is that it prunes some historic artifacts from the Lisp family tree. Clojure adds more artifacts than it removes. > Lisp was developed as a direct improvement over assembly. Lisp was developed for symbolic computation with recursive functions in the domain of list processing. It has nothing to do with assembler. > It's a rethinking of what a Lisp needs (when backwards compatibility is ignored). It's a rethinking what a Java programmer might want as the next step. As Lisp not so much. > It's an interesting design. That's true.
- mcguire 12y agoI've only briefly played with Clojure and it's been a very long time since I used Common Lisp a lot, but... "Can you explain why this has parentheses: ([x] x) ?" For the same reason "((= a 2) (setq a 3))" has parentheses in: (cond ((= a 1) (setq a 2)) ((= a 2) (setq a 3))
- lgas 12y agoCan you explain why "((= a 2) (setq a 3))" has parentheses in that statement? Ideally without just saying "for the same reason as <some other example>"? Because I don't see any value in having them in that example. (cond (= a 1) (setq a 2) (= a 2) (setq a 3)) Seems like it could serve exactly the same purpose?
- mcguire 12y ago
- klibertp 12y agoOh, but you're wrong I believe. In Clojure, as well as in most other lisps, this: '(1 2 3) constructs a value of type list, while this: [1 2 3] constructs a value of type vector. They are not the same and you cannot say that one somehow becomes the other. And from what I remember Clojure does have a list data-type and it still needs to be quoted, except for empty list literal, (), which is self-evaluating. So, in Clojure you need to quote your lists, exactly like in many other Lisps, and you have literals for other data structures, exactly like in many other Lisps ([] in Elisp, #() in Racket, CL covered by lispm). But of course Clojure is so much more readable because it has so few parentheses in comparison... to Java, I suppose.
- brudgers 12y agoFor what it's worth, using quoted lists is not considered idiomatic in Clojure (so be forewarned it might get you voted off the island). Also (let [my-list '(1 2 3) my-vec [1 2 3] (= my-list my-vec)) returns `true`. It's one of the subtleties of Clojure and its implementation on top of Java's object and type systems, and one which can be difficult to parse out at the lower end of the learning curve...which is where I am.
- klibertp 12y agoBut that's besides the point I tried to make, which is that pretty much ALL Lisps include more syntax than just pure s-exps. You may like one version better than other, but saying that Clojure is the only Lisp with "revised syntax" or "syntax designed for readability" is silly. Clojure is a member of Lisp family and it's a formidable and worthy member at that. But it's not as ground-breaking or unique as some people would like to think - the family is vast and multi-generational and many things were already tried in some form or the other. I still like Clojure's particular view on Lispiness, though.
- brudgers 12y agosilly Finding a rationale for calling other people silly seems more like the point you were trying to make. To the point of attributing statements and beliefs to me that I neither stated nor indicated I held.