Subject: Re: The inverse of optional arguments. From: Erik Naggum <erik@naggum.no> Date: 2000/02/22 Newsgroups: comp.lang.lisp Message-ID: <3160236064663586@naggum.no> * Jon Haugsand <Jon.Haugsand@nr.no> | Maybe I am blind, but I cannot find out a way to do the following. I | have a function that has a function parameter where the latter is called | with some arguments. However I would like to call it with more arguments | if the function would accept them. An example: | | (defun mydo (proc) | (apply proc (list :extra 5))) | | (mydo #'(lambda (&key (extra 0)) (+ 4 extra))) | (mydo #'(lambda () 4)) | | The first call to MYDO works, however I would like something like the | second too, where APPLY simply should ignore extra parameters when not | required. first, you need to make sure that the function you're calling has &key in its argument list. then, you call it with :allow-other-keys t in its argument list. this will silence the default action for unknown keyword arguments. the function function-lambda-expression should return the lambda expression for the function in question, but it is allowed to return nil for any function, so you're a little out of luck without special support for this thing. in Allegro CL, however, the function excl:arglist returns the argument list of the function, as it was known when the function was compiled (which may not be the verbatim argument list due to macro "preprocessing"). this is usually sufficient to see whether you have a keyword-argument-accepting function. however, the general problem you're tring to solve is more interesting: figuring out how to express a "protocol" for functions that accept functions as arguments and call them with something other than a trivial transformation of its own argument list. I believe this is partly what makes up the concept of "interface" in Java and it would be kind of nice if it were solved neatly for Common Lisp, too. #:Erik