Re: [Didier Verna] multiple string reads/writes of SB-IMPL::BAKQ-COMMA

Douglas Katzman <[email protected]> Fri, 11 Oct 2013 09:09:38 -0400
Newsgroups gmane.lisp.steel-bank.devel,gmane.lisp.cmucl.devel
Message-ID <CAOrNasySvgU8wzMcZoRbpDkioj4j0HJYDzqXAOd1QPFxWJmWrw@mail.gmail.com>
You'll get correct results doing it this way -

(with-input-from-string (s "(defmacro test (&body body)

           (let ((obj (gensym)))

             `(let (,obj)

                (setq ,obj (list ,@body))

                ,obj)))")
           (eval (with-input-from-string
                   (s (write-to-string (read s) :pretty nil :readably t))
                   (read s))))




On Fri, Oct 11, 2013 at 4:27 AM, Didier Verna <[email protected]> wrote:

>
>   Hi,
>
> on second thought, I'm forwarding this to sbcl-devel because I think
> this might be a bug. The same scenario works fine with CCL. CMUCL gives
> a note and a warning but still works:
>
> CL-USER> (test 'a 'b)
> ; In: TEST 'A
>
> ;   (TEST 'A 'B)
> ; ==>
> ;   (LET (#)
> ;     (SETQ #:G0 #)
> ;     #:G0)
> ; Note: Variable LISP::BACKQ-COMMA defined but never used.
> ; ;
>
> ; Warning: These variables are undefined:
> ;   #:G0 OBJ
> ; (A B)
>
> The macroepansion is however similar to that of SBCL:
>
> CL-USER> (macroexpand '(test 'a 'b))
> (LET ((LISP::BACKQ-COMMA OBJ))
>   (SETQ #:G4368 (LIST 'A 'B))
>   #:G4368)
> T
>
>
>
>
>
>
> ---------- Forwarded message ----------
> From: Didier Verna <[email protected]>
> To: SBCL Help <[email protected]>
> Cc:
> Date: Fri, 11 Oct 2013 09:14:06 +0200
> Subject: multiple string reads/writes of SB-IMPL::BAKQ-COMMA
>
>   Hello,
>
> the backquote syntax gives me a problem when doing multiple (in fact 2)
> reads and writes of an expression. Consider this:
>
> CL-USER> (defmacro test (&body body)
>            (let ((obj (gensym)))
>              `(let (,obj)
>                 (setq ,obj (list ,@body))
>                 ,obj)))
> TEST
> CL-USER> (test 'foo 'bar)
> (FOO BAR)
>
>
> CL-USER> (with-input-from-string (s "(defmacro test (&body body)
>            (let ((obj (gensym)))
>              `(let (,obj)
>                 (setq ,obj (list ,@body))
>                 ,obj)))")
>            (eval (read s)))
> STYLE-WARNING: redefining COMMON-LISP-USER::TEST in DEFMACRO
> TEST
> CL-USER> (test 'foo 'bar)
> (FOO BAR)
>
> ;; Okay, but then...
>
>
> CL-USER> (with-input-from-string (s "(defmacro test (&body body)
>            (let ((obj (gensym)))
>              `(let (,obj)
>                 (setq ,obj (list ,@body))
>                 ,obj)))")
>            (eval (with-input-from-string (s (prin1-to-string (read s)))
>                    (read s))))
> STYLE-WARNING: redefining COMMON-LISP-USER::TEST in DEFMACRO
> TEST
> CL-USER> (test 'foo 'bar)
> ; in: TEST 'FOO
> ;     (LET ((SB-IMPL::BACKQ-COMMA OBJ))
> ;       (SETQ #:G2191 (LIST 'FOO 'BAR))
> ;       #:G2191)
> ;
> ; caught STYLE-WARNING:
> ;   The variable SB-IMPL::BACKQ-COMMA is defined but never used.
>
> ;     (SETQ #:G2191 (LIST 'FOO 'BAR))
> ;
> ; caught WARNING:
> ;   undefined variable: #:G2191
>
>
> and it breaks. What happens is that in the first case, SBCL understands
> that (SB-IMPL::BACKQ-COMMA OBJ) really means ,obj in the let form, but
> if I read this expression, write it to a string and read it again for
> evaluation, then it thinks that I'm trying to bind SB-IMPL::BACKQ-COMMA
> to OBJ...
>
>
> How can I avoid this behavior ?
>
>
> Thanks !
>
> --
> Resistance is futile. You will be jazzimilated.
>
> Lisp, Jazz, Aïkido: http://www.didierverna.info
>
>
>
> --
> Resistance is futile. You will be jazzimilated.
>
> Lisp, Jazz, Aïkido: http://www.didierverna.info
>
>
> ------------------------------------------------------------------------------
> October Webinars: Code for Performance
> Free Intel webinars can help you accelerate application performance.
> Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most
> from
> the latest Intel processors and coprocessors. See abstracts and register >
> http://pubads.g.doubleclick.net/gampad/clk?id=60134071&iu=/4140/ostg.clktrk
> _______________________________________________
> Sbcl-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/sbcl-devel
>
>

------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134071&iu=/4140/ostg.clktrk

_______________________________________________
Sbcl-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sbcl-devel