[racket] Bouncing default value

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Sat Feb 11 12:00:52 EST 2012

FWIW, reasons like this is why most of the standard libraries have #f or
some other simple value for a default. Then, the "real" default is computed
in the body.


On Saturday, February 11, 2012, Laurent <laurent.orseau at gmail.com> wrote:
> Hi,
> Often I'd like to make a wrapper for a given function that has default
values (possibly with keywords).
> So if I want my function to have the same default values for one
particular optional argument, I need to redefine it myself.
> For example, suppose there already exists a function foo like this:
> (define (foo arg1 [arg2 <some-complicated-default-value>])
>   ....)
> And I want to make a wrapper for foo on arg1, but keep foo's arg2 default
> (define (bar [arg2 <the-same-complicated-default-value>])
>   (foo 5 arg2))
> But I don't feel right when I need to redefine the default argument, for
a few reasons:
> - I feel bar should not need to know foo's arg2 default value.
> - if arg2 has a complicated default argument, it is "painful" and
error-prone to rewrite it (and if the docs for the default value for arg2
are simplified, it may be problematic),
> - if the specification of foo's arg2 changes, I need to change bar too
(though sometimes bar's arg2 needs not reflect the change, but often it
> I would prefer something like:
> (define (bar [arg2 (get-default-value foo arg2)])
>   (foo 5 arg2))
> which is transparent w.r.t. foo.
> Does this feature exist, or does it even have a name? Or can it be easily
implemented (maybe keywords could help)?
> Thanks,
> Laurent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120211/e3c5aa12/attachment.html>

Posted on the users mailing list.