4 ms·
TXR Lisp keeps a weak hash table which associates objects in the syntax with file/line information, without changing their representation in any way. There is
by kazinator 6y ago
TXR Lisp keeps a weak hash table which associates objects in the syntax with file/line information, without changing their representation in any way.
There is no need for ugly, cumbersome syntax objects that destroy Lisp.
Whether or not the recording of source loc info is enabled is controlled by a special variable. It is disabled by default, because you probably don't want that overhead if you're calling the reader for reams of data. Functions like compile-file and load enable it locally.
To take advantage of the info for error reporting in a user defined macro, you can simply do this:
(defmacro mymacro (:form f arg1 arg2 ...) ;; get the form using :form
(when (somehow-no-good arg1) ;; something wrong with arguments
(compile-error f "first argument ~s is no good!" arg1))
...)
You get an error which mentions mymacro, and the location.
(foo.lisp:10) mymacro: first argument 42 is no good!
- xscott 6y agoThis is interesting and clever - thank you for sharing it. However, it seems like the hash table would work on either the address or the shape of the code, and in either case you could build a pathological case which would break it. It's probably a really nice solution for the common/realistic case though.