On Feb 19, 1:12 pm, Chris Perkins <chrisperkin...@gmail.com> wrote: > On Feb 19, 4:32 am, timc <timgcl...@gmail.com> wrote: > > Is #= an undocumented reader macro character? > > Interesting - I had never heard of it either. It appears to allow you > to execute code at read-time. > > user=> (read-string "(foo (+ 2 3) bar)") > (foo (+ 2 3) bar) > user=> (read-string "(foo #=(+ 2 3) bar)") > (foo 5 bar) > > I guess the ability to disable it with *read-eval* is something to do > with reading from an untrusted source. > > I can't, off the top of my head, think of how I would use this. I > thought the ability to run code at macro-expansion time was cool > enough - now I find out I can do it at read-time too!
One use was easy serialization. That might not be so obvious in Clojure; but in Common Lisp, objects are often left machine- unreadable. Take how a 3D point might print: CL: #<point (1,2,3)> Clojure: {:x 1, :y 2, :z 3} (Anyone who's unwittingly printed a gigantic xml-zip at the repl might see the merits in the CL approach. ;) So for cheap serialization, you'd write it out to stream like this, to later read it back in: ;; in CL it's #. and not #= ;; http://www.pentaside.org/paper/persistence-lemmens.txt (format stream "#.(MAKE-INSTANCE 'POINT :X ~S :Y ~S :Z ~S)" x y z) Another use is optimization... you could compute (or partially compute) a big ol' table of info at read-time. I believe *read-eval*'s (aka "read-evil") default value of true is a gaping security hole, though perhaps I'm missing a good justification for it. All the best, Tj -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en