

Clojure's mini languages - silkodyssey
http://blog.fogus.me/2010/03/23/clojures-mini-languages/

======
ekiru
I don't really understand how the Clojure syntax-quote somehow prevents name-
capturing any more than that of Common Lisp does(except for the foo# gensym
shortcut). The Common Lisp backquote automatically qualifies symbols in the
current package. In fact, the Common Lisp reader does that for all symbols
used without a qualified namespace. It would be terribly painful to write in
any language with a mandatory package system which could not infer the package
to which a symbol belongs in this way.

What makes Clojure's backquote so much more resilient against variable capture
than Common Lisp's?

~~~
apgwoz
I've often wondered this. Last week rich hickey mentioned this at clojure NYC,
and they only things he mentioned were the fully qualifying namespaces (which
resolves to the original package it was defined in) and the auto gensyms. I
assume this is enough in most cases and the auto gensyms take care of the
rest. I don't think I'd trust namespace rewriting by itself though.

~~~
fogus
Right, and one without the other doesn't do the trick. You need both auto-
gensyms and namespace resolution to ensure hygiene in Clojure macros (cleanly
at least). On the other hand as lg mentioned you can intentionally capture
using the pattern described. So you get the best of both worlds with the
stipulation that the case of intentional capture is a bit more cumbersome.

------
mark_l_watson
Nice. I bought a MEAP of Fogus' Clojure book: I assume that all of his mini-
articles will be in the book.

~~~
fogus
I'm trying not to recycle the blog posts, but in some ways it's impossible.
This specific post will not make it in, but all of the topics will be covered
where applicable. Thanks for buying the MEAP; I hope you like it so far.

------
peregrine
His site has a console mode...and its pretty awesome. I've never really heard
great things about "The Joy of X" books but if the books are as excellent as
his blog posts I may have to chip in.

~~~
thomas_a_berlin
I feel a bit sorry to ask but : how does one access a site in "console mode" ?

~~~
peregrine
In the head of the site look for this "Run This Blog In Mobile Or Console
Mode..." click Console mode.

------
delluminatus
Hey, pretty cool. I had no idea about the (-> ... ... ) macro. I loved how F#
(and Haskell) made that same thing really easy, but it turns out Clojure did
too. Heh.

Now if only I could get it working on Windows.

------
projectileboy
I realize this has nothing to do with the content of your post, but your blog
has the best title of all time.

------
nearestneighbor
It starts with

> _one of the strengths of Clojure is that it is comprised of many little
> mini-languages_

and ends with (in the comments)

> _I hope you do not judge the whole of Clojure by this blog post_

So which is it? Is this syntactic soup an achievement to be proud of or a
misfeature to ignore and avoid?

~~~
swannodette
> _So which is it? Is this syntactic soup an achievement to be proud of or a
> misfeature to ignore and avoid?_

Most of those things listed are neither, rather they are pragmatic and
intended to _improve_ readability.

    
    
      * List comprehensions need no justification.
      * Literal regex support also needs no justification.
      * Syntax quote needs no justification.
      * Literal numerics need no justification.
    

Stuff you might not use:

    
    
      * pre/post conditions
      * gen-class
    

I hardly consider ns a mini-language any more than I consider any language's
import syntax a mini-language but that's me.

So we're left with #() and ->, ->>.

#() is often abused. It's really meant for things like this:

    
    
      (map #(* % 3) (range 100))
      ; vs.
      (map (fn [x] (* x 3)) (range 100))
    

It's intended to improve readability when used properly.

This the purpose of -> and ->> as well. People often complain that Lisp code
needs to be read inside out.

    
    
      (+ (* (/ x 2) 3) 5))
      ; vs.
      (-> x (/ 2) (* 3) (+ 5))
    

Again a readability win, not loss.

~~~
nearestneighbor
> _Most of those things listed are neither, rather they are pragmatic and
> intended to improve readability._

The road to damnation is paved with good intentions. In C++, (which I use a
lot for many practical reasons), _separately_ every single feature solves or
improves something, but _together_ the improvements could have been made more
consistently at a lesser cost in language elegance.

~~~
swannodette
_separately every single feature solves or improves something, but together
the improvements could have been made more consistently at a lesser cost in
language elegance._

The problem with C++ is that those "improvements" are _grafted_ onto the
language. You can't do a _damn thing_ about it.

In Clojure half these "mini-languages" are just macros. You don't have to use
any of it. If you see a better way to do things build your own macros from the
primitive forms.

Good luck fixing C++ :D

~~~
nearestneighbor
> _The problem with C++ is that those "improvements" are grafted onto the
> language. You can't do a damn thing about it._

You don't have to use the features you don't like. Its main design principle
is "you don't pay for what you don't use".

The problem with C++ is that too many people who don't know it, talk about it
:-P

------
brianobush
500 error :(

~~~
fogus
I was playing on the server at the time... should be fine now.

