From ... From: Erik Naggum Subject: Re: The inverse of optional arguments. Date: 2000/02/22 Message-ID: <3160236064663586@naggum.no>#1/1 X-Deja-AN: 588538787 References: mail-copies-to: never Content-Type: text/plain; charset=us-ascii X-Complaints-To: newsmaster@eunet.no X-Trace: oslo-nntp.eunet.no 951252149 24004 195.0.192.66 (22 Feb 2000 20:42:29 GMT) Organization: Naggum Software; +47 8800 8879 or +1 510 435 8604; fax: +47 2210 9077; http://www.naggum.no User-Agent: Gnus/5.0803 (Gnus v5.8.3) Emacs/20.5 Mime-Version: 1.0 NNTP-Posting-Date: 22 Feb 2000 20:42:29 GMT Newsgroups: comp.lang.lisp * Jon Haugsand | 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