>> So, what are people's thoughts?
>
> Trying to use them in Common Lisp has frustrated the crap out of me.  
> The only library I know of that promulgates them seriously is CL-SQL  
> and the gymnastics you have to do to install the reader macros are  
> frustrating. Another library I tried to use I couldn't get to work  
> at all (units, I think).

AllegroGraph uses ! as a reader macro to introduce URIs and RDF  
literals, which means they appear quite frequently in user code. You  
can write

!rdf:type
!<http://example.com/foo>
!"chien"@fr

and the appropriate object (a so-called future-part) is integrated  
directly into the read code, just like a string or a list. This has  
three advantages over something like

(resource "rdf" "type")

—

* This process happens at read-time, which means that you can use this  
syntax in *unevaluated* positions, such as in macros, query forms that  
are only read, not evaluated, etc. That can be really convenient.

* The syntax is much closer to the conventional syntax used in  
serialization formats (simply add a '!' to the front of the usual  
syntax). Users who are more familiar with Java or Python don't seem to  
mind, which is not true when you add parentheses to your syntax.

* You can raise a syntax error at read time, rather than at compile-  
or run-time. That's a nice feature in a dynamic language, where you  
might not know your code is broken until much later. It's nice for  
DSLs to have distinct syntax and semantics, and requiring the use of  
macros or functions to implicitly construct syntactic elements blurs  
that line.

I've observed this in the discrepancy between the 'primary' Clojure  
types, such as set, map, et al, which have syntax, and those which do  
not: sorted-set or struct-map, for example.

However, for all these benefits I'm still not sure whether it would be  
worthwhile allowing user-generated reader macros. They are absolute  
hell when integrating conflicting libraries — it only takes one major  
library to use a reader macro character, and it's pretty much verboten  
for all other libraries, just in case you want to combine them.

Franz's Allegro Common Lisp offers a workaround for this problem —  
named readtables, which makes using readtables in CL much tidier. If a  
library's readtable does not take effect in user code until demanded,  
then conflicts do not occur. Code that uses libraries with conflicting  
syntax can be partitioned to use different readtables.

If it were possible to signal to Clojure's reader which readtable to  
use when reading a file/stream/string, and readtables were named in a  
similar manner to namespaces, and could be composed, then I think user- 
defined reader macros would be safe and convenient. Just as in-ns and  
ns adjust the current namespace, they could adjust the readtable:

(ns com.example.foo
   (:refer-clojure)
   (:use com.example.library1)
   (:readtables
     clojure.core
     com.example.library1))


I'm sure this would complicate Clojure's reader significantly.

-R
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to