help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: macroexpansion and (function ...)


From: Faried Nawaz
Subject: Re: macroexpansion and (function ...)
Date: 11 Jul 2003 06:28:42 -0700

Barry Margolin <barry.margolin@level3.com> wrote in message 
news:<2llPa.11$0z4.7@news.level3.com>...

> Macros don't evaluate their arguments.  A macro's expansion can't depend on
> runtime data, because macros will be expanded by the compiler.

I knew that.  Really, I did.

I have to pass the fn as a symbol, but that's not an issue.  This works for
my app:

(defun trigger-register (name regex response-fn response-string)
  (add-to-table name `(lambda () (,response-fn ,response-string)) regex))

I somehow missed the subtlety there.


Thanks,

Faried.
ps: someone asked about for-each.  Noah Friedman wrote it; I've been loading
it in my startup files somewhere for years and forgot that it's not part of
x?emacs:

(defun for-each (fn &rest lists)
  "Like mapcar, but don't cons a list of return values.
This function also handles multiple list arguments.
The first arg, a function, is expected to take as many arguments as there
are subsequent list arguments to for-each, and each argument list is
assumed to be the same length."
  (cond ((consp (cdr lists))
         (let ((listrun (make-list (length lists) nil))
               listsl listrunl)
           (while (car lists)
             (setq listrunl listrun)
             (setq listsl lists)
             (while listsl
               (setcar listrunl (car (car listsl)))
               (setcar listsl (cdr (car listsl)))
               (setq listrunl (cdr listrunl))
               (setq listsl (cdr listsl)))
             (apply fn listrun))))
        (t
         ;; Speed/minimal-consing hack for when there is only one arglist.
         (setq lists (car lists))
         (while lists
           (funcall fn (car lists))
           (setq lists (cdr lists))))))

;; eof


reply via email to

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