Re: programmatically determine if argument is list compatible to a given lambda list



jimka wrote:
even after getting rid of the lexical binding problem, i'd like to
tell sbcl that i'm not interesting in
seeing the other comments. any ideas?



(defun callable-as (arg-list lambda-list)
(declare (sb-ext:muffle-conditions sb-ext:compiler-note))
(handler-case (apply (coerce `(lambda ,lambda-list
t)
'function)
arg-list)
(program-error () nil)))

TYPE> (callable-as '(3) '(x))
; #'(LAMBDA (TYPE::X) T)
;
; caught STYLE-WARNING:
; The variable X is defined but never used.
;
; compilation unit finished
; caught 1 STYLE-WARNING condition
T
TYPE>

Hm, maybe:

(defun callable-as-p (arg-list lambda-list)
(handler-case
(apply
(handler-bind ((style-warning #'muffle-warning))
(locally (declare (optimize (safety 3)))
(coerce `(lambda ,lambda-list t) 'function)))
arg-list)
(program-error () nil)))


The coercion happens at runtime, so the sb-ext:muffle-conditions declaration probably doesn't have any effect here, because the latter only applies at compile time.


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/
.