[Ecls-list] Ecls-list digest, Vol 1 #330 - 1 msg

Pascal J.Bourguignon pjb at informatimago.com
Fri Nov 19 08:13:03 UTC 2004

ecls-list-request at lists.sourceforge.net writes:
> Date: Thu, 18 Nov 2004 16:50:25 +0100
> From: "Goffioul Michael" <goffioul at imec.be>
> To: <ecls-list at lists.sourceforge.net>
> Subject: [Ecls-list] set-macro-character doesn't affect current reader??
> Hi,
> I tried to create a macro reader for '$' in ECL using the
> following code:
> (defvar +database+ (make-hash-table))
> (setf (gethash 's1 +database+) "value1")
> (setf (gethash 's2 +database+) "value2")
> (defun dollar-macro-reader (stream char)
>   (declare (ignore char))
>   (let ((sym (read stream t nil t)))
>     `(gethash ',sym +database+)))
> (set-macro-character #\$ #'dollar-macro-reader t)
> (print $s1)
> Then I use it in ECL prompt as in the following session:
> ECL (Embeddable Common-Lisp) 0.9d
> Copyright (C) 1984 Taiichi Yuasa and Masami Hagiya
> Copyright (C) 1993 Giuseppe Attardi
> Copyright (C) 2000 Juan J. Garcia-Ripoll
>         ECL is free software, and you are welcome to redistribute it
> under certain conditions; see file 'Copyright' for details.
> Type :h for Help.  Top level.
> > (load "testmacro")
> ;;; Loading #P"testmacro.lisp"
> "value1"
> #P"testmacro.lisp"
> Top level.
> > (print $s1)
> The variable $S1 is unbound.
> Broken at EVAL.
> As you can see, during the loading, the new macro character is
> used, but not from the prompt. Trying this under CLISP, it works
> fine. Is this a bug or the intended behavior?

CLSH says:

     load binds *readtable* and *package* to the values they held
     before loading the file.

so modifications to the current readtable inside the loaded file are
not kept.

Usually, I find that it's better to edit a copy of the readtable and
let the user use it at will:

Inside the file:

(defparameter *custom-readtable* (copy-readtable nil))
(set-macro-character character function nil *custom-readtable*)
(setf *readtable* *custom-readtable*)

Outside the file:

(load "custom")

(defparameter *saved-readtable* *readtable*)
(setf *readtable* *custom-readtable*)
(setf *readtable* *saved-readtable*)


(let ((*readtable* *custom-readtable*))

__Pascal Bourguignon__                     http://www.informatimago.com/
The world will now reboot; don't bother saving your artefacts.

More information about the ecl-devel mailing list