FSet supplies reader macros so that collection expressions can be written in source code in syntax
similar to that in which they are printed. I first wrote these years ago, thinking that I wanted to
use them, but I never have; as things have turned out, I prefer simply calling the constructor
macros, which are in ordinary, parenthesized Lisp syntax. (Here are the constructor macros, for
reference: set, ch-set, wb-set, map, ch-map, wb-map, bag, ch-bag,
wb-bag, seq, replay-set, replay-map, 2-relation, ch-2-relation, and wb-2-relation.)
The reader macros come in two flavors, which I’ll call the “constructor” type and the “rereading” type. The “constructor” reader macros expand to calls to the constructor macros. This means that symbols and lists within them will be evaluated. I think this is probably the behavior that will be most often desired when writing code, but it means that printing an FSet collection and then reading it back is unlikely to have the desired effect, unless all of the elements of the collection are self-evaluating in Common Lisp: numbers, strings, and keyword symbols.
The “rereading” reader macros are provided to handle the case where you want round-trip
equivalence, so you can read a printed structure containing FSet collections, and get a structure
equal? to the one you started with.
There are three ways to use the reader macros. The recommended way is using Named-Readtables:
(named-readtables:in-readtable fset2:fset-readtable) ;; or (named-readtables:in-readtable fset2:fset-rereading-readtable)
If you wish to make further customizations, and you’re using Named-Readtables, the recommended
approach is to supply one of these names in the :merge clause of a
named-readtables:defreadtable form.
If you don’t want to use Named-Readtables, there are two other ways. You can set or bind
*readtable* to either *fset-readtable* or *fset-rereading-readtable*. Or, if
you have an existing, customized readtable that you want to add FSet reader macros to, call
fset-setup-readtable or fset-setup-rereading-readtable on it.
The syntax accepted by the rereading reader macros is, naturally, the same as that produced by
printing; see the table above. The syntax accepted by the constructor
reading macros is very similar, except that (as of this writing) they do not accept comparison
functions or defaults. They also accept the syntax #$expr; it reads as ($
expr), which is interpreted by the constructor macros as a union or splice, that treats the
value of expr as a sub-collection of the same kind and uses its elements or pairs.