> * In message <Pine.LNX.4.44.0303150053390.20127-100000@...>
> * On the subject of "[clisp-list] Re: New, from-scratch implementation of backquote."
> * Sent on Sat, 15 Mar 2003 01:45:18 -0800 (PST)
> * Honorable Kaz Kylheku <kaz@...> writes:
> I have reimplemented backquotes in CLISP from scratch; the work is
> advanced far enough that I can rebuild the patched CLISP and pass
> ``make test''.
> The aim is to produce a smaller, simpler, more elegant implementation
> that has zero defects.
Did you check that the two defects are gone:
1. in backquote.lisp;
;; Bug: With nested backquotes some partial forms are evaluated several
;; times (e.g. in the primary evaluation: forms, which are needed for
;; the interpretation of secondary evaluation forms) and should
;; therefore be free from side-effects.
Multiple backquote combinations like ,,@ or ,@,@ are not
implemented. Their use would be confusing anyway.
> A few visible differences are introduced.
> Firstly, the reader macros no longer perform expansion. Consequently,
> the SYSTEM::BACKQUOTE macro does not have a second argument that
> specifies the expanded form. The job of expansion, rather, is moved
> into the macro itself. So we now have a thick macro, but a thin reader
> macro rather than the other way around.
this appears to be the more standard approach.
> The structure of the SYSTEM::BACKQUOTE forms has changed in another
> way. The ,@FORM syntax corresponds to (SPLICE FORM) rather than (SPLICE
> (UNQUOTE FORM)). The special case (SPLICE FORM) to represent ,@'FORM is
> gone, this is just (SPLICE (QUOTE FORM)). In other words, this is more
> like the Scheme scheme. Of course, I adjusted the pretty printer
> accordingly by removing code that parses the two cases of the SPLICE
> Any code that depends on CLISP's representation of ,@ will break.
> The SYSTEM::ADD-BACKQUOTE and SYSTEM::ADD-UNQUOTE interfaces continue
> to work. CLISP uses these internally, for instance in DEFSTRUCT,
> to generate backquotes.
> I removed the dependency from the array and struct readers on the
> SYSTEM::*BACKQUOTE-LEVEL* variable. A different trick is used to
> detect that an unquote has occured while reading a form other than a
> simple vector or list. This trick is not as perfect, in the
> sense that there are more opportunities for the sub-reader to become
> confused by the embedded UNQUOTE or SPLICE form, but but on the other
> hand, in other cases we can produce a more accurate error message than
> that a comma has occured outside of a backquote.
> I still have a few items to do:
> - the ,. destructive splicing syntax is not implemented as destructive
> syntax; it's semantically equivalent to ,@ right now.
> - the code generated by the backquote is not optimized; it
> does lots of atrocious consing like (append (list '1) (list '2)).
> - I have to conform the error messages to the internalization
> system in CLISP. Probably I will just reuse the existing ones,
> for the most part.
> - write some automated tests that exercise complex backquotes,
> like the ones that bugged out on me.
> If anyone is interested, I can provide a clean patch against the 2.30
released under GNU GPL?
> By the way. Let's try something:
> ;;; expected result: (FOO `(BAR (BAZ 'A A) (BAZ 'B B) ...))
> ;;; CLISP result: (FOO `(BAR NIL NIL NIL NIL))
> (defun breaks-on-clisp ()
> (let ((list '(a b c d)))
> `(foo `(bar ,@',(mapcar #'(lambda (sym)
> `(baz ',sym ,sym))
> > (breaks-on-clisp)
> (FOO (APPEND (LIST 'BAR) '((BAZ 'A A) (BAZ 'B B) (BAZ 'C C) (BAZ 'D D))))
> Woo hoo! Not bad for two evenings of hacking. ;)
> How about the pretty printer breakage, whereby the backquote is
> printed wrongly, but still evals right?
> ``,,`,3 ==> `,NIL (stock CLISP)
> ``,,`,3 ==> 3 (hacked CLISP)
> Score again! In fact, under the new hack, the ``,,`,FOO is completely
> reduced to FOO, watch this;
> (macroexpand '``,,`,FOO)
> ==> FOO ; T
Sam Steingold (http://www.podval.org/~sds) running RedHat8 GNU/Linux
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
Good programmers treat Microsoft products as damage and route around it.