···@zedat.fu-berlin.de (Stefan Ram) wrote:
> ( combine f g h x )
I'm new to Lisp, but I think you should quote the function names, because
usually you expect variable evaluation if you write an identifier:
(combine 'f 'g 'h x). Now my first solution with a list:
(defun combine-list (funlist arg)
(if funlist
(funcall (car funlist)(combine-list (cdr funlist) arg))
arg))
You can use it like this: (combine-list '(f g h) x)
It is easy to write another function, which accepts the arguments not in
a list:
(defun combine (&rest funlist-with-arg)
(combine-list
(butlast funlist-with-arg)
(car (last funlist-with-arg))))
An usage example:
(defun f (x) (* 2 x))
(defun g (x) (+ 1 x))
(combine 'f 'g (lambda (x) (* 3)) 1)
I think in Scheme it would be easier to do such things, but I'm sure my
solution with functions instead of macros could be done easier in Lisp,
too.
--
Frank Bu�, ··@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de
In article <············@newsreader2.netcologne.de>,
Frank Buss <··@frank-buss.de> wrote:
> ···@zedat.fu-berlin.de (Stefan Ram) wrote:
>
> > ( combine f g h x )
>
> I'm new to Lisp, but I think you should quote the function names, because
> usually you expect variable evaluation if you write an identifier:
> (combine 'f 'g 'h x). Now my first solution with a list:
Actually, you should use FUNCTION, not QUOTE, i.e.
(combine #'f #'h #'h x)
Otherwise, it won't work with local functions.
--
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***