Re: programmatically determine if argument is list compatible to a given lambda list
- From: jimka <jimka@xxxxxxxxx>
- Date: 28 Apr 2007 13:54:30 -0700
if i try that in sbcl, this is what happens. (callable-as '(3) '(x
y))
invalid number of arguments: 1
[Condition of type SB-INT:SIMPLE-PROGRAM-ERROR]
Restarts:
0: [ABORT-REQUEST] Abort handling SLIME request.
1: [TERMINATE-THREAD] Terminate this thread (#<THREAD "repl-
thread" {10010910F1}>)
Backtrace:
0: ((LAMBDA (X Y)) #<unavailable argument>)
1: (CALLABLE-AS (3) (X Y))
2: (SB-INT:EVAL-IN-LEXENV (CALLABLE-AS (QUOTE (3)) (QUOTE (X Y)))
#<NULL-LEXENV>)
3: (SWANK::EVAL-REGION "(callable-as '(3) '(x y))
" T)
On Apr 28, 10:46 pm, Pascal Costanza <p...@xxxxxxxxx> wrote:
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:
- 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: splicing with subst
- 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):