Re: Newbie question: writing a composer function in Lisp
- From: "Dimiter \"malkia\" Stanev" <malkia@xxxxxxxxx>
- Date: Tue, 18 Sep 2007 22:04:10 -0700
Hi,
Code:
(defun my-compose (&rest function-list)
(if (= 1 (length function-list))
#'(lambda(x) (funcall (car function-list) x))
#'(lambda(x) (funcall (car function-list) (funcall (my-
compose (cdr function-list)) x)))))
If you change car to caar, it would work:
(defun my-compose (&rest function-list)
(if (= 1 (length function-list))
#'(lambda(x) (funcall (caar function-list) x))
#'(lambda(x) (funcall (caar function-list)
(funcall (my-compose (cdr function-list)) x)))))
But it won't be correct.
The problem is that you are using (&rest function-list), which would would put all the rest arguments in list itself, and that's why you need double car - caar.
In fact, you don't need (&rest function-list), so the correct solution is:
(defun my-compose (function-list)
(if (= 1 (length function-list))
#'(lambda(x) (funcall (car function-list) x))
#'(lambda(x) (funcall (car function-list)
(funcall (my-compose (cdr function-list)) x)))))
Thanks,
Dimiter "malkia" Stanev.
.
- References:
- Newbie question: writing a composer function in Lisp
- From: srinik001
- Newbie question: writing a composer function in Lisp
- Prev by Date: Newbie question: writing a composer function in Lisp
- Next by Date: Re: Newbie question: writing a composer function in Lisp
- Previous by thread: Newbie question: writing a composer function in Lisp
- Next by thread: Re: Newbie question: writing a composer function in Lisp
- Index(es):
Relevant Pages
|