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

compiler-let and macrolet in macros



    Date:     Mon, 10 Mar 86 19:14:01 PST
    From: Jeff Barnett <jbarnett%NRTC@USC-ECL.ARPA>

    Consider the following hack.
      (defmacro with-car (&body body)
	`(compiler-let((operator 'car))
	   ,. body))
      (defmacro with-cdr (&body body)
	`(compiler-let((operator 'cdr))
	   ,. body))
      (defmacro right-side (exp) `(,operator ,exp))
    What I want to know is will the following work
      (setf (with-car (right-side foo)) (with-cdr (right-side goo)))
    Probably not.  Of course this can be transformed into
      (with-car (setf (right-side foo) (with-cdr (right-side goo))))
    However, I think the latter is more obscure.

(define-setf-method compiler-let (bindings single-body-form)
  (progv (mapcar #'first bindings)
	 (mapcar #'eval (mapcar #'second bindings))
	 (get-setf-method-multiple-value single-body-form)))

makes it work for me.  Perhaps if I thought about it more I would come up
with a subtle reason why this works for your example but cannot work in the
most general case.  Perhaps it should wrap the COMPILER-LET back around
the fourth and fifth values before returning them.

The reason define-setf-method is included in the language is precisely to
provide a portable way to do hairy things like this.

    By the way, I don't believe
    that an implementation of this sort using macrolet will work either.

I think it would if Common Lisp included a portable way to manipulate the function
environment in the same way that progv provides a portable way to manipulate the
special-variable environment.