kawa-commonlisp-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Kawa-commonlisp-dev] [GSoC] Destructuring bind


From: Helmut Eller
Subject: Re: [Kawa-commonlisp-dev] [GSoC] Destructuring bind
Date: Tue, 31 Jul 2012 09:19:26 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux)

On Tue, Jul 31 2012, Charles Turner wrote:

> This is a follow on from discussions on the previous list.
>
> I am slowly moving code from SBCL. One subtlety of their
> implementation is that parse-defmacro uses destructuring-bind and
> destructuring-bind use parse-defmacro. I'm told (foom, #sbcl
> (freenode)) that parse-defmacro is compiled and that
>
> "a working destructuring-bind macro only needed to exist in the
> *compiler* for it to be compiled into the right function."
>
> I didn't fully understand this. Maybe a bootstrapping trick, I don't
> know.

Remember that macros are expanded at compile time and the compiled code
doesn't need the macro definition.  SBCL is a meta-circular
implementation, i.e. the SBCL compiler is compiled by another CL
compiler. That makes some things easier.  The other compiler already has
a working DESTRUCTURING-BIND so they are free to use it in the SBCL
source code.

It's not much different when Clang is compiled with GCC: the Clang
source code can use all C++ features, even if Clang itself doesn't
support them yet.  What matters is that GCC supports the feature.

> But for me, it seems like one of these functions will be best
> implemented in Java, or else do I need to employ some sort of
> bootstrap build? Maybe I can get away with it? The problem is
> src/code/destructuring-bind.lisp calls src/code/parse-defmacro.lisp,
> and parse-defmacro-lambda-list in parse-defmacro.lisp calls
> destructuring-bind.lisp.
>
> Am I misunderstanding something?

The only use of DESTRUCTURING-BIND in parse-defmacro.lisp seems
to be this:

(destructuring-bind (varname &optional default-form suppliedp-name) var
   ...)

Doing that manually isn't that hard:

(when (> (length var) 3) (error "Invalid syntax for &optional arg"))
(let ((varname (car var))
      (default-form (cadr var))
      (suppliedp-name (caddr var)))
  ...)

Also CMUCL's version of parse-defmacro-lambda-list uses no
DESTRUCTURING-BIND at all:
http://common-lisp.net/gitweb?p=projects/cmucl/cmucl.git;a=blob_plain;f=src/code/defmacro.lisp;hb=HEAD

Rewriting everything in Java is an option, but IHMO it's
more elegant to write as much in Lisp as possible.

Helmut



reply via email to

[Prev in Thread] Current Thread [Next in Thread]