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



Alan Crowe wrote:
Pascal Costanza <pc@xxxxxxxxx> writes:

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?


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)))


Seeing Pascal's handler for program-error made me think of
the third value from COMPILE

CL-USER> (let ((*error-output* (make-broadcast-stream)))
(compile nil '(lambda() ((lambda(&key a b )nil) :a 3 ))))
#<Function "LAMBDA NIL" {48A60019}>
T
NIL <-- OK so error=nil

CL-USER> (let ((*error-output* (make-broadcast-stream)))
(compile nil '(lambda() ((lambda(&key a b )nil) :a 3 :c 3))))
#<Function "LAMBDA NIL" {48AA49D1}>
T
T <-- :c not declared to error=T

I specifically went for coerce instead of compile because coerce may give you interpreted code while compile is required to do at least minimal compilation. Since these are one-off functions by definition, interpreted code is more efficient in this case - the overhead of compilation is not justified here, especially in implementations with slow compilers (like SBCL).

Having said that, I have to admit that I would have probably overlooked the additional return values of compile anway, so thanks for the hint. ;)


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



Relevant Pages

  • Re: (eval-when?)
    ... > - open the source file ... Because defconstant may have compile-time side-effects: ... In sbcl: ... An implementation may choose to evaluate the value-form at compile ...
    (comp.lang.lisp)
  • Re: Troll-o-Matic
    ... I am getting compile times of around 4s with SBCL 0.9.9. ... (The changes to the Lisp environment don't explain this change. ... [I've defined tokens as follows: ...
    (comp.lang.lisp)
  • Re: Newbie compilation problem
    ... When (using SBCL), I type (load "test.lisp"), then everything works fine. ... compile it, I get a slightly different result: ... try switching from defconstant to defvar. ...
    (comp.lang.lisp)
  • Re: Comparison Ruby, Python, Php, Groovy ecc.
    ... ...without the need to compile every interpreter. ... an implementation of ANSI Common Lisp. ... More information about SBCL is available at. ... Type HELP for debugger help, or to exit from SBCL. ...
    (comp.lang.ruby)
  • Macro compilation problem with Allegro
    ... I am trying to move to allegro in os-x, ... compile code that I've had working for years (sbcl in linux and ... warnings in sbcl, but fails to compile in Allegro with an "attempt to ...
    (comp.lang.lisp)