From: Jon Haugsand
Subject: The inverse of optional arguments.
Date: 
Message-ID: <yzod7ppbfr7.fsf@naos.nr.no>
Maybe I am blind, but I cannot find out a way to do the following. I
have a function that have 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.

-- 
Jon Haugsand
  Norwegian Computing Center, <http://www.nr.no/engelsk/> 
  <···················@nr.no>  Pho: +47 22852608 / +47 22852500, 
  Fax: +47 22697660, Pb 114 Blindern, N-0314 OSLO, Norway

From: Erik Naggum
Subject: Re: The inverse of optional arguments.
Date: 
Message-ID: <3160236064663586@naggum.no>
* 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
From: Raymond Wiker
Subject: Re: The inverse of optional arguments.
Date: 
Message-ID: <87u2j1v35h.fsf@foobar.orion.no>
Jon Haugsand <············@nr.no> writes:

> Maybe I am blind, but I cannot find out a way to do the following. I
> have a function that have 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.

        &allow-extra-keys? Alternatively, use &rest with or without
&key/&allow-other-keys.

-- 
Raymond Wiker, Orion Systems AS
+47 370 61150