News for hackers. Stuff that matters.
Re:The Weird and Wonderful Characters of Clojure by eudox on Monday May 19, 2014 @11:33AM (#7767919)
And here's how to use Common Lisp reader macros to implement JSON literals: https://gist.github.com/chaitanyagupta/9324402
Re:The Weird and Wonderful Characters of Clojure by emidln on Monday May 19, 2014 @11:04AM (#7767734)
I've been using Clojure for awhile now and it has never previously occurred to me that you could do:

    #(foo %2)
instead of

    (fn [_ arg2] (foo arg2))
Thanks!
Re:The Weird and Wonderful Characters of Clojure by yobriefcase on Monday May 19, 2014 @11:08AM (#7767764)
Neither did I until I started writing about #( and decided to see what would happen. The joys of being nosey.
Re:The Weird and Wonderful Characters of Clojure by da02 on Monday May 19, 2014 @11:51AM (#7768031)
Nosey? Or maybe "curious"? Explorer? Pioneer? Either way, thanks for writing about it.
Re:The Weird and Wonderful Characters of Clojure by moomin on Monday May 19, 2014 @02:45PM (#7769043)
Obviously, bear in mind that (comp foo second) may be preferable.
Re:The Weird and Wonderful Characters of Clojure by weavejester on Monday May 19, 2014 @03:09PM (#7769176)
Slightly different use-case, as:

    (comp foo second)
Is equivalent to:

    (fn [[_ x]] (foo x))
Not:

    (fn [_ x] (foo x))
Re:The Weird and Wonderful Characters of Clojure by ar7hur on Monday May 19, 2014 @04:05PM (#7769471)
+1.

How about:

   (comp foo second list)
Re:The Weird and Wonderful Characters of Clojure by Totient on Monday May 19, 2014 @12:47PM (#7768402)
I don't understand the difference between fn and fn* . After some brief experimenting in the REPL, they seem to behave exactly the same, the only difference being that fn* is what comes out of macro expanding the #( macro

Is there a reason that the #( macro doesn't expand to plain old fn?

Re:The Weird and Wonderful Characters of Clojure by MBlume on Monday May 19, 2014 @01:12PM (#7768535)
fn is a macro that knows how to apply destructuring rules, fn* is a primitive read by the clojure compiler and cannot apply destructuring rules.

https://github.com/clojure/clojure/blob/master/src/clj/cloju...

Re:The Weird and Wonderful Characters of Clojure by diego on Monday May 19, 2014 @01:18PM (#7768567)
fn itself is a macro, fn* is a symbol defined at the compiler level:

    static final Symbol FN = Symbol.intern("fn*");
Re:The Weird and Wonderful Characters of Clojure by programnature on Monday May 19, 2014 @11:13AM (#7767804)
The characters are hard to google, but I've found them sufficiently documented here: http://clojure.org/reader
Re:The Weird and Wonderful Characters of Clojure by kivikakk on Tuesday May 20, 2014 @03:00AM (#7771509)
It seems disingenuous to describe ";" as a "comment macro". It's not a macro, it just causes the reader to ignore characters until EOF, \r, or \n. (https://github.com/clojure/clojure/blob/master/src/jvm/cloju...)

The fact that the CommentReader is dispatched from a table called "macros" (https://github.com/clojure/clojure/blob/master/src/jvm/cloju...) means nothing, unless you also call string literals "string macros", s-expressions "s-exp macros", etc., since mostly everything is dispatched from that table.

Re:The Weird and Wonderful Characters of Clojure by moomin on Monday May 19, 2014 @10:56AM (#7767674)
Fun article. Should also add in #anything, and discover the weird and wonderful world of the extensible reader.
Re:The Weird and Wonderful Characters of Clojure by yobriefcase on Monday May 19, 2014 @10:59AM (#7767696)
If you can link me to some examples of this I'll be happy to add them.

(edit) I have a comment around the fact user defined reader macros are not supported in Clojure (save for a hack). Is this not the case anymore?

Re:The Weird and Wonderful Characters of Clojure by emidln on Monday May 19, 2014 @11:10AM (#7767782)
I think this is referring to the ability to the tagged literals api (set data-readers[1] and change/extend the various literal notations already provided by clojure (like #uuid and #inst)). The docs seem to believe that unqualified var names are reserved and you should fully-qualify your tags, but this seems to be more of a suggestion than a requirement.

[1][2]

    *data-readers* 
[2] http://clojure.github.io/clojure/clojure.core-api.html#cloju...
Re:The Weird and Wonderful Characters of Clojure by BostX on Monday May 19, 2014 @12:28PM (#7768275)
A big Thanx for this!
Re:The Weird and Wonderful Characters of Clojure by jcromartie on Monday May 19, 2014 @11:47AM (#7768005)
Does the author mean "character" in a literary sense? Because many of these things have better names, and in fact "character" is wholly incorrect for anything like "#_" or "#'" which consist of multiple characters.

Also, functions are not methods, and the terms are not interchangeable.

All of this is summarized in a much more succinct and correct fashion here: http://clojure.org/reader

Re:The Weird and Wonderful Characters of Clojure by masklinn on Monday May 19, 2014 @12:09PM (#7768155)
> and in fact "character" is wholly incorrect for anything like "#_" or "#'" which consist of multiple characters.

#_ is a character for the dispatch invocation, and a dispatch character. The way it's used in TFA is perfectly understandable.

> All of this is summarized in a much more succinct and correct fashion here: http://clojure.org/reader

Which uses the word "character" to describe them. And gives no examples, so it may be more succinct but is also of very limited use to people who have no idea what this is about. Those who know what it's about are not going to google for macro characters.

Re:The Weird and Wonderful Characters of Clojure by jcromartie on Monday May 19, 2014 @02:42PM (#7769033)
The word "character" is used to describe them because they are certainly made of characters. The most generic term for everything but the macro characters themselves is "form". The dispatch macro is a special case that is not a form, but represents reader macros that are applied to forms as they are read. Same goes for quoting. But all of the specific cases of #_ or #{ or #" etc. are more than just characters.

And the docs do in fact give plenty of examples. I'm not sure how you can say "no examples" when there are examples for most of the things described on the page.

It may be dense, but the writing is clear and you can just read it start to finish.

EDIT: I see what you mean about "macro characters".

Just to be as clear as possible:

# - a macro character which dispatches on the next character

#{:foo :bar} - a hash-set literal form

#(...) - an anonymous function literal form

' - the quote character

'foo - a quoted symbol form

-> - the threading macro (just a normal symbol)

(-> x inc str) - a form using the threading macro

Re:The Weird and Wonderful Characters of Clojure by masklinn on Monday May 19, 2014 @03:48PM (#7769395)
> The word "character" is used to describe them because they are certainly made of characters.

In OP, the word "character" is used because they're characters and they're hard to search for when you don't know clojure and you're trying to understand what the hell this crazy crap is. So the goal is to match "clojure $something character", something along those lines.

> The dispatch macro is a special case that is not a form, but represents reader macros that are applied to forms as they are read.

Yes, but that's missing the purpose of OP. If you don't know that ' is `quote`, what do you do?

> And the docs do in fact give plenty of examples. I'm not sure how you can say "no examples" when there are examples for most of the things described on the page.

No, the docs give no example aside from metadata (and even then it's not great) and syntax-quote. For other macro characters it gives the expansion, no example and little to nothing in the way of explanation.

> Just to be as clear as possible:

Yes, the point being that those things are hard to search for

> #(...) - an anonymous function literal form

That's not a function literal form, `fn` is the function form (and `fn` a layer over it which handles binding forms), `#()` is a reader macro over that*.

Re:The Weird and Wonderful Characters of Clojure by jcromartie on Monday May 19, 2014 @04:20PM (#7769535)
Maybe I'm spoiled because when I started out with Clojure I just went to clojure.org and read it.

The only things on the OP's page without an explicit example on clojure.org/reader are: "#_", "%" for args, ";" for comments, and "$" as part of a class name.

Re:The Weird and Wonderful Characters of Clojure by beat on Monday May 19, 2014 @12:14PM (#7768183)
I think "token" would be more technically accurate.