Skip to content

Looking expansion

YOKOTA Yuki edited this page Apr 29, 2019 · 3 revisions

Let's look how to be expanded within #{ and }#.

(Examples in this page is based on 2019-04-26 version. Expansion results may be changed.)

In REPL

  1. quote it;
CL-USER> '#{ format (t, "Hello World!"); }#
(WITH-C-SYNTAX:WITH-C-SYNTAX (:KEYWORD-CASE :UPCASE)
  FORMAT
  |(|
  T
  |,|
  "Hello World!"
  |)|
  |;|)

(I think adding quote is a general way to seeing read-macro expansion.)

  1. macroexpand it;
CL-USER> (macroexpand *)
(PROGN (WITH-C-SYNTAX.CORE::REPLACE-OPERATOR-IF-NO-BINDINGS LOCALLY
         (LET* ()
           (DECLARE (DYNAMIC-EXTENT) (SPECIAL))
           (WITH-C-SYNTAX.CORE::REPLACE-OPERATOR-IF-NO-BINDINGS PROGN
             (LABELS ()
               (WITH-C-SYNTAX.CORE::REPLACE-OPERATOR-IF-NO-BINDINGS
                 PROGN
                 (WITH-C-SYNTAX.CORE::WITH-DYNAMIC-BOUND-SYMBOLS NIL
                   (SYMBOL-MACROLET ()
                     (BLOCK NIL
                       (TAGBODY
                           (RETURN (FORMAT T "Hello World!"))))))))))))
T

In SLIME

I often wraps it in with-c-syntax itself.

(with-c-syntax ()
  #{
  format (t, "Hello World!");
  }#)

And I type C-c C-m (slime-macroexpand-1). I see below in slime-macroexpansion buffer;

(WITH-C-SYNTAX (:KEYWORD-CASE :UPCASE)
  FORMAT
  |(|
  T
  |,|
  "Hello World!"
  |)|
  |;|)

Why with-c-syntax appeared again is because #{ makes its own with-c-syntax form and the outer one merges inner one's contents into its body.

When I type C-c C-m again, I will see the last result in "In REPL" example above.