[plt-scheme] passing-on keyword arguments

From: Rob Hunter (rob.hunter at gmail.com)
Date: Tue Mar 18 14:49:49 EDT 2008

Let me elaborate:  If, for example, I had a way of passing an "absent"
value for a keyword argument, then I could do this with functions:

(define (inner #:x [x 10]) (* x x))

(define (outer #:x [x ABSENT-VAL]) (+ (inner #:x x) 5))

The semantics of ABSENT-VAL are such that if it is passed as a keyword
argument's val, then it as if I never set that keyword arg, and thus
the default value for it would be used.

--rob



On Tue, Mar 18, 2008 at 11:45 AM, Rob Hunter <rob.hunter at gmail.com> wrote:
> Thanks. I may end up doing that.  The downside is that I'm creating a
>  macro for something that  "feels" like it could just be an ordinary
>  function.
>
>  --rob
>
>
>
>
>  On Tue, Mar 18, 2008 at 11:38 AM, Matthias Felleisen
>  <matthias at ccs.neu.edu> wrote:
>  >
>  >  Macros?
>  >
>  >
>  >
>  >  On Mar 18, 2008, at 1:36 PM, Rob Hunter wrote:
>  >
>  >  > I've run into this issue a few times, and thought I'd finally post
>  >  > here.  I'd like to wrap a function that takes keyword arguments, but
>  >  > pass-on some/all of the keyword arguments from the outer function to
>  >  > the inner function.  For example,
>  >  >
>  >  > (define (inner #:x [x 10]) (* x x))
>  >  >
>  >  > (define (outer #:x [x 10]) (+ (inner #:x x) 5))
>  >  >
>  >  > This works, but I'm duplicating code.  Specifically, I had to
>  >  > duplicate the default value for the "x" argument.  Any nice way of
>  >  > writing outer and letting it defer to inner to get the default value
>  >  > for x?
>  >  >
>  >  > Thanks,
>  >  > Rob
>  >  > _________________________________________________
>  >  >   For list-related administrative tasks:
>  >  >   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>  >
>  >
>


Posted on the users mailing list.