News for hackers. Stuff that matters.
Re:You already use Lisp syntax by praptak on Wednesday May 21, 2014 @07:29AM (#7777638)
For me there were one and a half tricks to get Lisp syntax.

The first was the mental conversion to/from f(a,b,c) to (f a b c) which is just moving the opening parenthesis one token to the left and seeing both commas and whitespace as "something between the tokens that really matter".

The remaining half was starting with Clojure. It is a Lisp whose constructs are really optimized towards dumping extraneous parentheses so it is easier not to get lost in the nesting levels.

Re:You already use Lisp syntax by brudgers on Wednesday May 21, 2014 @08:38AM (#7777867)
To me, right now, I think the core difference between Clojure and other Lisps is Clojure gets rid of memory management. Yes, other Lisps have automatic deallocation, but the fundamental constructor, `cons`, is a raw memory allocation. It`s `malloc`for linked rather than sequential memory.

Although Clojure still has a `cons` it has been replaced by `seq` as the fundamental abstraction. Clojure takes advantage of being fully managed code and in a sense is as much a Lisp as C# is a C [if we were inclined to think of C as a genre, else Algol?].

It seems this, combined with a formally incorporating a DSL of the kind a experienced Lisper (such as Hickey) might create for writing programs gives Clojure it's syntax: e.g. [x y] is syntactically like a quoted list and writing a macro is the sort of thing hubris drives lazy impatient Lispers to do. In special forms [x y] is like a different more complex macro, but again the sort of thing people would write for themselves. In other Lisps the ad hoc nature of such macros however makes other people's code notoriously hard to follow.

Re:You already use Lisp syntax by wes-exp on Wednesday May 21, 2014 @02:59PM (#7780066)
`cons`, is a raw memory allocation. It`s `malloc`for linked rather than sequential memory

Yeah, cons is like malloc, except that the object it creates is automatically memory managed / garbage collected. There is no corresponding "free" call. Actually, that means cons is not like malloc.

Clojure takes advantage of being fully managed code

Do you realize that Lisp uses automatic memory management (just like the JVM or CLR)?

Re:You already use Lisp syntax by brudgers on Wednesday May 21, 2014 @06:11PM (#7781066)
Lisp's are high level languages. The JVM and CLR are virtual machines that interpret and compile bytecode. Some Lisps utilize virtual machines, Clojure being an example of one which does not use it's own, CMULisp and Racket are examples of Lisps which use their own VM, and ClozureCL and SBCL are Lisps which compile directly to native code. How Chicken Scheme fits into the whole virtual machine model...well it's just too fine an ontological line for me to call.

Why are there no Fortran machines or Algol Machines or C machines?

The `cons` cell is a raw memory structure, just one step removed from assembly and originally accessed directly in machine code with `car` and `cdr`. It's associated symbol is literally a pointer directly to a memory location. It's so close to assembly language that thirty years ago implementing it directly in hardware was considered practical.

Re:You already use Lisp syntax by wes-exp on Wednesday May 21, 2014 @08:38PM (#7781548)
The `cons` cell is a raw memory structure

It's associated symbol is literally a pointer directly to a memory location

A cons is not "raw memory"; it is a typed data structure, and in Common Lisp it is even considered an OOP object of the cons class. It is equivalent to having a data structure called "pair" that can hold two things.

All memory-allocated data structures ultimately have an address of some kind, so this whole discussion about pointers is utterly meaningless. For that matter, arrays, strings, and basically every known memory data structure is "raw" too. After all, they have an address.

The fact that cons/car/cdr can be implemented cheaply in hardware stems from the fixed and small size of cons. That doesn't make it somehow inferior.

By the way, the Java stuff is implemented in hardware too, does that make Java inferior? http://en.wikipedia.org/wiki/Java_processor

Re:You already use Lisp syntax by lispm on Wednesday May 21, 2014 @09:08AM (#7777974)
Clojure constructs don't allocate memory - okay...

> Although Clojure still has a `cons` it has been replaced by `seq` as the fundamental abstraction.

Common Lisp has lists and sequences as abstractions. But it does not take away the low-level operations.

Re:You already use Lisp syntax by brudgers on Wednesday May 21, 2014 @09:32AM (#7778073)
Sorry for not writing more clearly. Because Clojure does not need to allocate memory, it can use `seq` as its fundamental constructor. A `seq` is anything that implements `first` and `next`, it's a higher level abstraction than `cons` because it frees up `()` and `nil` from `car` and `cdr` [or `first` and `rest`]. At a higher level the abstraction facilitates differentiating a breadth first search tree from a depth first search tree as types of data structures (though I'm not necessarily advocating the idea). Sure it could be done in a traditional Lisp but the best case sausage factory is probably less sanitary.

I'm not making a case that Clojure is better than other Lisps - getting rid of `cons` and relying on the JVM has makes typing more critical in an environment that retains a degree of type opacity typical of dynamic type systems.

Re:You already use Lisp syntax by lispm on Wednesday May 21, 2014 @09:45AM (#7778148)
> A `seq` is anything that implements `first` and `next`, it's a higher level abstraction than `cons` because it frees up `()` and `nil` from `car` and `cdr` [or `first` and `rest`].

See SERIES in Common Lisp. http://series.sourceforge.net

> At a higher level the abstraction facilitates differentiating a breadth first search tree from a depth first search tree as types of data structures

Typically used as CLOS libraries in Common Lisp.

> getting rid of `cons`

That's caused because Clojure is implemented in something else and doesn't go very deep.

Common Lisp goes deeper because it is it's own implementation language. Much of the implementations are written in Common Lisp itself (compiler, parts of the runtime, ...). On something like the MIT Lisp Machine even the garbage collector was written in Lisp.

Lisp is reflective building material + machineries + some pre-build stuff.

Clojure is more like pre-built stuff on top of some other infrastructure.

Re:You already use Lisp syntax by brudgers on Wednesday May 21, 2014 @10:21AM (#7778365)
I'm not advancing a moral argument. I'm advancing an historical one. It's an amoral fact that Common Lisp was standardized more than twenty years ago - before the commercial internet, wide availability of systems suitable for distributed computing, and even before it was clear that GUI's would win the war. Moreover, the last standardization was grounded in the previous effort and that was before GNU and when dedicated hardware looked like the future. And that first standardization was the result of peace talks between tribes that had developed customs over the previous two decades (or thereabouts).

All that said, what Clojure shares with Common Lisp, is that practical programming issues come first and that theology comes last - in the end all questions of doctrine can be resolved in the mathematics of the lambda calculus.

Clojure and Common Lisp express the same attitude toward programming and programmers. Their attitude toward academic computer science is perhaps a bit different, largely for reasons of history: Lisp has one, Clojure doesn't.

Re:You already use Lisp syntax by lispm on Wednesday May 21, 2014 @10:46AM (#7778503)
You'll try a partial rewrite of the history. Common Lisp was developed over the Internet. The participating groups were all nicely networked and had lots of distributed systems. XEROX PARC and MIT pioneered the GUI. Lisp Machines were the first workstations with GUIs commercially available in 1981. Common Lisp came with its own native binding of X11 - CLX from day one.

> Moreover, the last standardization was grounded in the previous effort and that was before GNU and when dedicated hardware looked like the future.

Hmm, Common Lisp was developed to run efficiently on stock hardware from day one. Motorola 68k, Intel 86, then SPARC, POWER, MIPS, ...

> Clojure and Common Lisp express the same attitude toward programming and programmers.

They don't.

Common Lisp was developed as a standard Lisp language for application development (in domains like expert systems, cad systems, etc.) which favors giving the programmer maximum freedom and makes little assumption on what it is running.

Example: Common Lisp comes with minimal expression syntax and an extension mechanism.

Clojure was originally developed to bring a Lisp to the JVM, which integrates with Java, reuses parts of Java and favors things like functional or concurrent programming.

Example: Clojure comes with more complex expression syntax and no extension mechanism.

Re:You already use Lisp syntax by brudgers on Wednesday May 21, 2014 @01:54PM (#7779687)
Re: rewriting

I stated that Common Lisp was developed before the commercial internet & args.

Re:You already use Lisp syntax by lispm on Wednesday May 21, 2014 @02:41PM (#7779966)
Let's see:

symbolics.com, Lisp Machine manufacturer, first ever .com domain. In 1985.

bbn.com, Lisp Machine developer, second .com domain in 1985.

Thinking Machines, Parallel AI Machine for Lisp, third .com domain in 1985

MCC, had hundreds of Lisp Machines, fourth .com domain in 1985

DEC, co-sponsor of CL, fifth .com domain in 1985

Xerox, Lisp Machine developer, seventh .com domain in 1986

...

I'd say all the companies who participated in the CL development from 1981-1994 were commercial entities on the Internet. All of them offered a variety of network services in their operating systems: mail, chat, terminal, X11, file sharing, remote printing, remote booting, name server, ...

http://en.wikipedia.org/wiki/List_of_the_oldest_currently_re...

All were having networked machines and networked operating systems.

Re:You already use Lisp syntax by brudgers on Wednesday May 21, 2014 @04:53PM (#7780713)
Common Lisp: The Language Guy L. Steele, ISBN 093237641X Publisher: Digital Press, 1984

However, I am in no way implying that the creation of the .com TLD is the resolution of the phrase "commercial internet" in ordinary language & args.

Re:You already use Lisp syntax by lispm on Wednesday May 21, 2014 @05:42PM (#7780935)
ANSI CL standard, published in 1994.

You wrote:

> I'm not advancing a moral argument. I'm advancing an historical one. It's an amoral fact that Common Lisp was standardized more than twenty years ago

It was standardized 1994 with the ANSI CL standard. Exactly 20 years ago.

> - before the commercial internet,

Commercial ISPs started around 1989.

> wide availability of systems suitable for distributed computing,

Distributed computing was available earlier.

> and even before it was clear that GUI's would win the war.

Lisp supported GUIs much earlier. The Common Lisp standards group had even a subgroup for this topic.

Anyway it's not clear what this all means, when CL was developed. Scheme, Objective C, C, C++, Smalltalk, were all developed before Common Lisp. What follows from that?

Re:You already use Lisp syntax by eudox on Wednesday May 21, 2014 @09:25AM (#7778040)
>`cons`, is a raw memory allocation. It`s `malloc`for linked rather than sequential memory.

>Clojure takes advantage of being fully managed code

>writing a macro is the sort of thing hubris drives lazy impatient Lispers to do

The ignorance of Clojure programmers is really incredible.

Re:You already use Lisp syntax by brudgers on Wednesday May 21, 2014 @09:34AM (#7778086)
Re:You already use Lisp syntax by ScottBurson on Wednesday May 21, 2014 @03:18PM (#7780167)
Okay, that covers eudox's third point, but the first two are still valid. Your claim that Clojure does something fundamentally different from Lisp when it comes to memory allocation is misinformed and, frankly, bizarre. And I have no idea what your point about managed code is -- Lisp code runs in a Lisp environment the same way that JVM or CLR code does.
Re:You already use Lisp syntax by jeremiep on Wednesday May 21, 2014 @08:22AM (#7777793)
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])

Re:You already use Lisp syntax by lispm on Wednesday May 21, 2014 @09:11AM (#7777983)
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)
Re:You already use Lisp syntax by brudgers on Wednesday May 21, 2014 @10:03AM (#7778248)
What 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.

Re:You already use Lisp syntax by lispm on Wednesday May 21, 2014 @10:24AM (#7778378)
Lisp 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.

Re:You already use Lisp syntax by mcguire on Wednesday May 21, 2014 @01:16PM (#7779416)
I'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))
Re:You already use Lisp syntax by lgas on Wednesday May 21, 2014 @02:02PM (#7779736)
Can 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?
Re:You already use Lisp syntax by mcguire on Wednesday May 21, 2014 @06:08PM (#7781052)
I 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...

Re:You already use Lisp syntax by bdonlan on Wednesday May 28, 2014 @04:34AM (#7808956)
In 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).
Re:You already use Lisp syntax by lispm on Wednesday May 21, 2014 @02:19PM (#7779832)
So we have a language called Clojure which groups by

   (... ([x] x) ([x x] x) ...); where there are complex evaluation rules...
and

   [x1 x2 x3], where all x are evaluated
and [v1 e1 v2 e2 ...], where only e is evaluated, in LET

and

   [v1 ... vn], where no v is evaluated, in argument lists
etc., etc.

I somehow fail to see the dramatic improvement over just using parentheses. Instead of learning building basic rules of forming and naming expressions with parentheses, I now learn a few inconsistent rules of forming and expressions with a set of delimiters - which is no problem, but it is not the huge progress you claim.

Re:You already use Lisp syntax by mcguire on Wednesday May 21, 2014 @06:11PM (#7781068)
You may be misunderstanding me. I don't claim any progress at all. Only trade-offs and fuzzy areas and lesser or greater poor decisions.
Re:You already use Lisp syntax by klibertp on Wednesday May 21, 2014 @10:41AM (#7778466)
I 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.
Re:You already use Lisp syntax by brudgers on Wednesday May 21, 2014 @02:16PM (#7779812)
Your 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.

Re:You already use Lisp syntax by klibertp on Wednesday May 21, 2014 @06:01PM (#7781022)
> 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?

Re:You already use Lisp syntax by brudgers on Wednesday May 21, 2014 @06:33PM (#7781153)
It's not for readability in Clojure. [+ 1 2] and (+ 1 2) and '(+ 1 2) all evaluate to different values. The closest are [+ 1 2] and '(+ 1 2) as arguments to anything but `eval` or `seq?`. Under `eval` '(+ 1 2) is identical to (+ 1 2) under `seq?` [+ 1 2] and (+ 1 2) both evaluate to false.

As I said it's complicated.

In Racket on the other hand `))))))` is equivalent to `)))]]]` except in so far as matching goes. The brackets are just decorations.

Re:You already use Lisp syntax by klibertp on Wednesday May 21, 2014 @10:18AM (#7778345)
Oh, 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.

Re:You already use Lisp syntax by brudgers on Wednesday May 21, 2014 @10:27AM (#7778395)
For 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.
Re:You already use Lisp syntax by klibertp on Wednesday May 21, 2014 @10:49AM (#7778522)
But 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.

Re:You already use Lisp syntax by brudgers on Wednesday May 21, 2014 @01:49PM (#7779640)
silly

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.

Re:You already use Lisp syntax by klibertp on Wednesday May 21, 2014 @06:07PM (#7781045)
Sorry if it looked like that, I didn't mean it as directed to you personally, it was more to jeremiep above and even more to the Clojure community at large, where it's easy to encounter such views.
Re:You already use Lisp syntax by brudgers on Wednesday May 21, 2014 @07:06PM (#7781274)
Sorry if it looked like that looks kind of like an apology, but isn't.

The opening line of the first paragraph of your comment directly referred to the content of my post and the last word in that paragraph was silly.

Now understand I'm in my 20th year of internet use, so it's not the most uncivil thing that's ever been said to me. It's not even close to a rather mild incivility that I might have written a few years ago.

But it is uncivil and out of keeping with HN's community standards. There are plenty of other places that not only accept but tacitly encourage posts with that rhetorical flavor. But that's not HN.

https://news.ycombinator.com/item?id=7253493

Re:You already use Lisp syntax by lispm on Wednesday May 21, 2014 @12:07PM (#7778969)

   (let [my-list '(1 2 3)
         my-vec   [1 2 3]
     (= my-list my-vec))
That syntax is wrong. It lacks a closing ].