Re: programmatically determine if argument is list compatible to a given lambda list
- From: Pascal Costanza <pc@xxxxxxxxx>
- Date: Sun, 29 Apr 2007 21:24:03 +0200
Pascal Bourguignon wrote:
jimka <jimka@xxxxxxxxx> writes:
I'd like to write a function which at run-time will determine whether
a given list
of arguments is compatible to a given lambda list.
For example.
(callable-as '(3) '(x))
==> return t because you CAN apply (lambda (x) nil) to '(3)
(callable-as '(3) '(x &rest y))
==> return t because you CAN apply (lambda (x &rest y) nil) to '(3)
(callable-as '(3) '(x y))
==> return nil because you CANNOT apply (lambda (x y) nil) to '(3)
Here is my attempt which fails miserably.
(defun callable-as (arg-list lambda-list)
(unwind-protect (apply `(lambda ,lambda-list
(return-from callable-as t))
arg-list)
(return-from callable-as nil)))
This is dangerous.
What if the lambda list is:
(x &optional (y (delete-file "/some/important/file")))
to not write anything worse ?
You can call any function with (delete-file "/bla") as one of its parameters. ?!?
Pascal
--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
.
- Follow-Ups:
- Re: programmatically determine if argument is list compatible to a given lambda list
- From: Pascal Bourguignon
- Re: programmatically determine if argument is list compatible to a given lambda list
- References:
- Prev by Date: Re: programmatically determine if argument is list compatible to a given lambda list
- Next by Date: Re: programmatically determine if argument is list compatible to a given lambda list
- Previous by thread: Re: programmatically determine if argument is list compatible to a given lambda list
- Next by thread: Re: programmatically determine if argument is list compatible to a given lambda list
- Index(es):