Re: programmatically determine if argument is list compatible to a given lambda list
- From: Pascal Costanza <pc@xxxxxxxxx>
- Date: Sat, 28 Apr 2007 23:15:11 +0200
jimka wrote:
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)
Ah, of course. You should use handler-case, not unwind-protect:
(defun callable-as (arg-list lambda-list)
(handler-case (apply (coerce `(lambda ,lambda-list
(return-from callable-as t))
'function)
arg-list)
(program-error () nil)))
You should probably also make sure that the safety settings are correct at the time when coerce is executed. (See 3.5.1.1 in the HyperSpec.)
Finally, the lambda expression is embedded in the null lexical environment, so it doesn't see the 'callable-as block. But it should be good enough to just return 't from the lambda expression - you don't need to be specific about where to return from.
Finally, it might make sense to consider a macro version - if the lambda lists are quoted constants all of the time, a macro can be more efficient. (Or you could define a compiler macro.)
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: 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):
Relevant Pages
|
|