Re: programmatically determine if argument is list compatible to a given lambda list
- From: Pascal Bourguignon <pjb@xxxxxxxxxxxxxxxxx>
- Date: Sun, 29 Apr 2007 21:17:37 +0200
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 ?
I would rather parse the lambda list and check the parameters
myself. See: PARSE-LAMBDA-LIST in:
http://darcs.informatimago.com/darcs/public/lisp/common-lisp/source-form.lisp
--
__Pascal Bourguignon__ http://www.informatimago.com/
COMPONENT EQUIVALENCY NOTICE: The subatomic particles (electrons,
protons, etc.) comprising this product are exactly the same in every
measurable respect as those used in the products of other
manufacturers, and no claim to the contrary may legitimately be
expressed or implied.
.
- Follow-Ups:
- Re: programmatically determine if argument is list compatible to a given lambda list
- From: Pascal Costanza
- Re: programmatically determine if argument is list compatible to a given lambda list
- References:
- Prev by Date: Re: how to pronounce BOUND
- 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):