Re: [racket] Bouncing default value

2012-02-14 Thread Laurent
> > > (define default (gensym)) > > (define (default? x) (equal? x default)) > > (Using `eq?' here is a common idiom.) > ah, of course, thanks for the reminder. > > In any case, the real point here is not the macro -- it's the > existence of a special `none' value that marks an unsupplied value.

Re: [racket] Bouncing default value

2012-02-14 Thread Laurent
On Tue, Feb 14, 2012 at 17:45, Chongkai Zhu wrote: > I simply use > > (define (bar . x) > (apply foo 5 x)) > Yes, but that does not work if the specified optional argument is not the first one (and not the last one). That works if all default arguments are all keyword-based though (using keywor

Re: [racket] Bouncing default value

2012-02-14 Thread Chongkai Zhu
On 2/11/2012 10:55 AM, Laurent 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

Re: [racket] Bouncing default value

2012-02-14 Thread Chongkai Zhu
On 2/11/2012 10:55 AM, Laurent 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

Re: [racket] Bouncing default value

2012-02-12 Thread Eli Barzilay
9 hours ago, Laurent wrote: > Thank you all for your good and helpful answers. Based on them, > here is my current solution (without keywords), using macros to ease > the function definition: > > #lang racket > > (define default (gensym)) > (define (default? x) (equal? x default)) (Using `eq?'

Re: [racket] Bouncing default value

2012-02-12 Thread Laurent
Thank you all for your good and helpful answers. Based on them, here is my current solution (without keywords), using macros to ease the function definition: #lang racket (define default (gensym)) (define (default? x) (equal? x default)) (define-syntax parse-args-body (syntax-rules () ; w

Re: [racket] Bouncing default value

2012-02-11 Thread Eli Barzilay
Four hours ago, Laurent wrote: > > (define (foo arg1 [arg2 ]) > ) > > (define (bar [arg2 ]) > (foo 5 arg2)) Robby's suggestion is basically: (define (foo x [y #f]) (let ([y (or y )]) ...)) (define (bar [y #f]) (foo 5 y)) If #f is a valid value, the common way to deal

Re: [racket] Bouncing default value

2012-02-11 Thread Matthias Felleisen
Would this help you, suitable wrapped up as a macro: #lang racket (struct f (g default) #:property prop:procedure (struct-field-index g)) (define f* (f (lambda (x [y ((f-default f*))]) (+ x y)) (lambda () 99))) (define (f-wrapper f-ish) (lambda (g [d ((f-default f-ish))]) ;; all you need

Re: [racket] Bouncing default value

2012-02-11 Thread Rodolfo Carvalho
On Sat, Feb 11, 2012 at 15:07, Rodolfo Carvalho wrote: > Hello, > > On Sat, Feb 11, 2012 at 14:55, Laurent wrote: > >> ... >> >> (define (bar [arg2 (get-default-value foo arg2)]) >> (foo 5 arg2)) >> >> >> > Maybe someone will have a better idea (or a brighter implementation), but > if not, here

Re: [racket] Bouncing default value

2012-02-11 Thread Rodolfo Carvalho
Hello, On Sat, Feb 11, 2012 at 14:55, Laurent wrote: > ... > > (define (bar [arg2 (get-default-value foo arg2)]) > (foo 5 arg2)) > > > Maybe someone will have a better idea (or a brighter implementation), but if not, here's my contribution: #lang racket (require rackunit) (define (foo arg1 [

Re: [racket] Bouncing default value

2012-02-11 Thread Robby Findler
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. Robby On Saturday, February 11, 2012, Laurent wrote: > Hi, > Often I'd like to make a wrapper for a given function that has default va