[Top][All Lists]

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

Re: table.el

From: Miles Bader
Subject: Re: table.el
Date: 01 Dec 2001 18:50:48 +0900

Some more comments (without regard to whether this is actually a good
idea or not!):

> (defmacro run-wrappers (wrappers &rest body)
>   "Run wrapper functions in WRAPPERS.
> WRAPPERS is a symbol whose value is a list of functions"
>   (let ((wrapper-value (make-symbol "wrapper-value"))
>       (wrapper (make-symbol "wrapper"))
>       (wrappers-symbol (cadr wrappers)))
>     `(let* ((,wrapper-value (eval ,wrappers))
>           (,wrapper (car ,wrapper-value))
>           (,wrappers-symbol (cdr ,wrapper-value)))
>        (if ,wrapper-value
>          (funcall ,wrapper)
>        ,@body))))

Since this is really a special-form, you should make it look like one.

For instance, there's no point in quoting the name of the wrapper
variable if you _only_ allow a simple quoted value to be there.

Also, the conventional name of a special form like this is `with-...'.

Here's an alternative definition that I think is cleaner:

(defmacro with-wrappers (wrapper-form &rest body)
  "Invoke wrappers in WRAPPERS-VAR if present, otherwise execute forms in BODY.
WRAPPER-FORM looks like (WRAPPERS-VAR ARG...), where ARG... is the
list of arguments passed to each wrapper in list stored in WRAPPERS-VAR.
While calling each wrapper, WRAPPERS-VAR is bound to the cdr of the
list, so that recursive invocations of `with-wrappers' on the same
variable will result in each wrapper in the list being called."
  (let ((wrapper-var (car wrapper-form))
        (wrapper (make-symbol "wrapper")))
    `(if ,wrapper-var
         (let ((,wrapper (car ,wrapper-var))
               (,wrapper-var (cdr ,wrapper-var)))
           (funcall ,wrapper ,@(cdr wrapper-form)))

An example usage of this is:

  (defun kill-region (beg end)
    (with-wrappers (kill-region-wrappers beg end)
      ...ordinary kill-region stuff...))

I'm beginning to think that life is just one long Yoko Ono album; no rhyme
or reason, just a lot of incoherent shrieks and then it's over.  --Ian Wolff

reply via email to

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