[CM] optional arguments in Scheme

Heinrich Taube taube at illinois.edu
Thu May 9 04:07:08 PDT 2013


hi  if you use s7's define then you don't need OptKey at all because all arguments will be opt key:

> (define* (foo a b c d e)
   (list a b c d e))

> (foo )
(#f #f #f #f #f)

> (foo 1 2)

(1 2 #f #f #f)

> (foo 1 2 3 4 5)
(1 2 3 4 5)

> (foo 1 2 3 4 5 6)
>>> Error: foo: too many arguments: (1 2 3 4 5 6)



On May 9, 2013, at 2:30 AM, Antoine <antoinedaurat at googlemail.com> wrote:

> Hello,
> 
> I am having a hard time understanding optional arguments 
> in Scheme and could use a little help.
> I want to pass optional arguments, without having to write 
> the keywords and it seems that in that 
> case "&optkey" becomes an argument!...
> 
> 
> (define* (hiho a &optkey (b 0) (c 0))
> (+ a b c))
> 
> (hiho 1 12)
> 
> => 1
> 
> (hiho 1 12 1 1)
> 
> => 3
> 
> Neither s7 documentation nor Common Music's reference 
> or examples give an overview of the syntax 
> for optionals and rests arguments. Could you be kind enough 
> to point me the right direction? :)
> Thank you!
> 
> 
> _______________________________________________
> Cmdist mailing list
> Cmdist at ccrma.stanford.edu
> http://ccrma-mail.stanford.edu/mailman/listinfo/cmdist




More information about the Cmdist mailing list