[racket] (define (f (x y)) body) when y has a previous definition
D'OH. Sorry, I've been reading Common Lisp specs for so long that I
read [ x y ] as "and optionally x followed by y", not "a list of x and
y". I.e., I don't internally grok square brackets as parentheses.
That makes the definition of the define syntax in
http://docs.racket-lang.org/reference/define.html
arg = arg-id | [arg-id default-expr] | keyword arg-id | keyword
[arg-id default-expr]
much clearer.
Thanks, and sorry for the noise!
On Mon, Jun 23, 2014 at 9:29 AM, Tony Garnock-Jones <tonyg at ccs.neu.edu> wrote:
> On 06/23/2014 09:21 AM, Joshua TAYLOR wrote:
>>> (define y 2)
>>> (define (f (x y))
>> (print x)
>> (print y))
>>
>> Is this expected?
>
> You've stumbled across Racket's syntax for default values for arguments,
> a.k.a. optional arguments. [1]
>
> If I write
>
> (define (myproc [x "hello"]) ...)
>
> then if I call myproc with one argument, then x takes the value of that
> argument, and if I call myproc with no arguments, then x takes its
> default -- "hello".
>
> Your function,
>
> (define (f [x y]) ...)
>
> says "if x is omitted at the call site, then bind x to the value of the
> variable y for the body of f".
>
> Regards,
> Tony
>
> [1]
> http://docs.racket-lang.org/guide/contracts-general-functions.html?q=optional#%28part._contracts-optional%29
--
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/