Documentation of :: Notation?

42 views
Skip to first unread message

Randall R Schulz

unread,
Nov 29, 2008, 4:09:31 PM11/29/08
to clo...@googlegroups.com
Hi,

I came across the use of :: keyword notation in section 8.4 of
Programming Clojure (beta 3 PDF) and went to look for it on the Clojure
Web site, but it appears not to be mentioned there. I looked in the
Reader, Evaluation, Namespaces, API, Multimethods ('cause that's where
Stuart introduces it in his book) and even the "Differences with other
Lisps" pages.

Is it there somewhere I'm not seeing (or looking for) it?


Randall Schulz

Stuart Halloway

unread,
Nov 29, 2008, 6:04:09 PM11/29/08
to clo...@googlegroups.com
The only place I have seen it is on this list, when I asked Rich how
to get the code for that section of the book to work. :-)

Stuart

http://groups.google.com/group/clojure/browse_thread/thread/a88caa17b8d24008/77832fcda9a1e8fc?lnk=gst&q=multimethods+halloway#77832fcda9a1e8fc

Randall R Schulz

unread,
Nov 29, 2008, 6:26:37 PM11/29/08
to clo...@googlegroups.com
Thanks, Stuart,

On Saturday 29 November 2008 15:04, Stuart Halloway wrote:
> The only place I have seen it is on this list, when I asked Rich how
> to get the code for that section of the book to work. :-)

OK... Is it a legitimate part of Clojure's public specification, or is
it something that is (even more) subject to change (than other things
in a young language)?


I've read the whole book now, and the only other unexplained notation
I've found is "#=". The first appearance is on page 57 (use fixed-width
for optimum viewing)):

(meta #'meta)
-> {:arglists ([obj]), :name meta, :file "boot.clj",
:line 147, :ns #=(find-ns clojure),
^^^^^^^^^^^^^^^^^^^
:doc "..."}


I can't replicate this by evaluating (meta #'meta). What I see in that
place is ":ns #<Namespace clojure.core>". And while I find a place in
the Clojure code that emits the "#=" sequence, it's part of an
undocumented defmethod.

What does it mean? Is it meant to be readable? If I try to read that, I
get this (in a newly launched REPL):

user=> #=(find-ns clojure)
nil

By the way, I should point out I'm using the latest SVN revision of the
Clojure code.

> Stuart
>
> ...


Randall Schulz

Chouser

unread,
Nov 29, 2008, 8:00:59 PM11/29/08
to clo...@googlegroups.com
On Sat, Nov 29, 2008 at 6:26 PM, Randall R Schulz <rsc...@sonic.net> wrote:
>
> OK... Is it a legitimate part of Clojure's public specification, or is
> it something that is (even more) subject to change (than other things
> in a young language)?

The double-colon keyword prefix is a specific and supported feature, I
believe, introduced Jul 28, svn rev 962. Since this predates the last
release, I assume the lack of documentation is a simple oversight.
The details were posted to this group here:
http://groups.google.com/group/clojure/browse_frm/thread/9cc9926de1bdb128

> I've read the whole book now, and the only other unexplained notation
> I've found is "#=".

This is part of the print-dup work related to AOT. It is new since
the last release, and therefore not necessarily documented on the site
yet. You can see why it's useful by comparing the output of print-dup
on a sorted map vs. a hash map:

user=> (print-dup (sorted-map :a 1 :b 2) *out*)
#=(clojure.lang.PersistentTreeMap/create {:a 1, :b 2})nil
user=> (print-dup (hash-map :a 1 :b 2) *out*)
{:b 2, :a 1}nil

You can see that #= provides a syntax that allows the reader to
produce data structures that are duplicates of what was printed,
preserving the exact same type. This differs from normal printing
where all seqs print like lists and all maps print like hash-maps.

The specific use and meaning of #=() and #<> changed a few times over
the course of a few days. It settled down with #=() being produced
exclusively by print-dup, so I don't know how complete the
documentation will be for that. It's not meant for people to write or
read it, really. #<> is used by 'print' to indicate expressions that
cannot be read back in by 'read'. For example:

user=> (java.util.Date.)
#<Date Sat Nov 29 19:59:42 EST 2008>

Hope that helps make sense of things,
--Chouser

Stuart Halloway

unread,
Nov 29, 2008, 8:12:50 PM11/29/08
to clo...@googlegroups.com
> This is part of the print-dup work related to AOT. It is new since
> the last release, and therefore not necessarily documented on the site
> yet.

Some examples in the book may be out-of-date wrt this change. Feel
free to post any you spot to the errata page:

http://www.pragprog.com/titles/shcloj/errata

Thanks!
Stuart

Randall R Schulz

unread,
Nov 29, 2008, 8:31:12 PM11/29/08
to clo...@googlegroups.com
On Saturday 29 November 2008 17:00, Chouser wrote:

> On Sat, Nov 29, 2008 at 6:26 PM, Randall R Schulz wrote:
> > OK... Is it a legitimate part of Clojure's public specification, or
> > is it something that is (even more) subject to change (than other
> > things in a young language)?
>
> The double-colon keyword prefix is a specific and supported feature,
> I believe, introduced Jul 28, svn rev 962. Since this predates the
> last release, I assume the lack of documentation is a simple
> oversight. The details were posted to this group here:
><http://groups.google.com/group/clojure/browse_frm/thread/9cc9926de1bdb128>
>
> > I've read the whole book now, and the only other unexplained
> > notation I've found is "#=".
>
> This is part of the print-dup work related to AOT. It is new since
> the last release, and therefore not necessarily documented on the
> site yet. ...

>
> Hope that helps make sense of things,
> --Chouser

Thanks, Stuart and Chris (it's Chris, right?).

As the programming language that is Clojure seeps into my mind, I
realize what a beautiful thing it is. As I said to a friend a couple of
days ago, I'd demurred too long in choosing a language for the
extension / scripting / executive layer for my theorem prover, but when
I finally realized that Clojure was the way to go and started digging
in to the language and contemplated the design for that new addition to
my system, I quickly realized the tremendous power that Clojure brings.

Thanks to Rick H. and everyone else who has contributed to making
Clojure what it is now and what it will become over time.


Randall Schulz

Reply all
Reply to author
Forward
0 new messages