10 ms·
Just 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
by lispm 12y ago
Just 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 agoI really did mean to have a question mark at the end of my comment. I'm not actually sure of the answer. The initial thought would be for structure: cond takes any number of arguments, each made up of a conditional -> expression pair. Your suggestion, which is exactly my initial belief before it burned me back in the day, would make cond take an alternating list of conditions and expressions; clearly that's not nearly as beautiful. The structural argument is wrong, though, and your suggestion doesn't work at all. For what must have seemed practical reasons at the time, the expression side is an implicit PROGN, so you can do "((= a 2) (setq a 3) (setq b (potato)))".[1] Common Lisp has some wacky syntax. Large chunks of which are historically (hystorically?) path-dependent. Anyone who tells you otherwise risks calling up the viscous LOOP troll. In Clojure, the defmacro thingy looks like it takes muliple expressions after the params in the body there, so it needs ()'s around the individual cases. [1] http://www.lispworks.com/documentation/lw60/CLHS/Body/m_cond.htm http://www.lispworks.com/documentation/lw60/CLHS/Body/m_cond...
- bdonlan 12y agoIn clojure cond does not have those extra parenthesis - that's a LISPism. cond in clojure works like your example, except that clojure does not have setq. The reason you have those parenthesis on defmacro is that defmacro shares syntax with defn and fn for function declaration; in turn, these allow for multiple side-effecting statements in a function. For example: (defn my-function [args] (prn "Hello, world!") ; do something with side effects... args) ; then return a value This works fine in the single-dispatch case, but when you're declaring a function that takes multiple arities (with a different implementation dispatched for each), there's no way to tell where each arity ends and the next begins - after all, something like [args] is just data and could easily be a valid expression. The parenthesis are then needed to disambiguate where one arity ends and the next begins: (defn greet ([] (println "Hello, there!") (swap! greeting-count inc) :greeted) ([name] (println "Hello, " name) (swap! greeting-count inc) :greeted)) This is a space where clojure seems a bit inconsistent - let, fn, loop, and try all allow multiple expressions, while cond and if don't (but you can get it back using the (do) special form). This however does have some logic to it - let and loop get it for free as they don't need extra brackets to disambiguate, and for fn it's very helpful to be able to just chuck additional statements (debug prints, for example) at the top or bottom without having to wrap in (do). Plus it's free in the more-common single arity case, and keeping it around for multiple-arity keeps things internally consistent. On the other hand, if and cond would require disambiguating syntax to take additional statements regardless, and so that syntax might as well be (do).
- klibertp 12y agoI actually like the `let` syntax improvement in Clojure, although I like how Racket deals with this issue too, which is by using both () and [] (and possibly {}) as interchange-able. It looks like this then: (let ([x 1] [y 3]) (+ x y)) which is not too bad either.
- brudgers 12y agoYour mileage may vary. My experience with Racket's use of square brackets was different. When I first looked at Racket Code, I assumed square brackets had semantic significance (I'd seen some Lisps and Schemes and glanced at Clojure code snippets in addition to a number of non-lisp languages). I spent mental energy trying to identify why they were used one place and not another. It was only after a significant time that I realized they are merely stylistic flourishes. As I have written Racket code, I have found that square brackets get in the way. Don't misunderstand me, they look great when the are printed, but changing the internal structure of an expression requires changing concluding logic from '))])))' to ')))]))' that I've decided it's pain than gain. I'd rather just add another close parenthesis and move on to running tests than navigate character by character. I love Racket, don't misunderstand me. But the square brackets are a faster horse at best, not a bicycle.
- klibertp 12y ago> Don't misunderstand me, they look great when the are printed, but changing the internal structure of an expression requires changing concluding logic from '))])))' to ')))]))' that I've decided it's pain than gain. But how is this different from Clojure? You can have exactly the same problem there[1]. Whenever you introduce irregularity to the syntax you're going to have these issues. Clojure does it for "readability" and so does Racket. The difference is that in Racket you can opt-out and only use normal parens, while you can't do this in Clojure - which is probably fine in their respective cases, as they target a bit different audiences I think. [1] But you do use an editor which makes this kind of problem impossible to occur, right? Like Emacs with Paredit or DrRacket with correct settings?
- 12y ago