Re: programmatically determine if argument is list compatible to a given lambda list
- From: Pascal Costanza <pc@xxxxxxxxx>
- Date: Sat, 28 Apr 2007 22:46:09 +0200
jimka wrote:
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)))
....but it's quite close:
(defun callable-as (arg-list lambda-list)
(unwind-protect (apply (coerce `(lambda ,lambda-list
(return-from callable-as t))
'function)
arg-list)
(return-from callable-as nil)))
[untested]
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:
- References:
- Prev by Date: Re: Problems with slime and cmucl
- Next by Date: Re: splicing with subst
- Previous by thread: 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):
Relevant Pages
|