Thanks, that's helpful

I am having trouble coming up with a quick and easy shorthand to recur on the 
rest parameter - is there a standard way to cdr down this list without an 
intermediary helper function that takes out the raise-nesting-depth effect? 

Recursion on the base define (the one with the rest parameter) always adds 
another layer of nesting for the rest parameter - the first time recurring one 
must cdr, all the other times one must fiddle with car & cdr and what I'm doing 
has been prone working for the first few iterations but eventually 
arity-mismatches.


On Tuesday, September 6, 2016 at 7:39:59 AM UTC-4, gneuner2 wrote:
> On Sun, 4 Sep 2016 10:36:21 -0700 (PDT), Sanjeev Sharma wrote: 
> 
> >two "x" 's also work
> >
> >(define list (lambda x x))
> 
> (lambda x x x) works because the evaluation of the middle x is a side
> effect which is ignored.  It still will work if you change it to,
> e.g., (lambda x 'q x)  or (lambda x 42 x) ... changing the middle x to
> anything that is not a variable.
> 
> 
> Extra information:   [ignore if you know this already]
> 
> (lambda x x) is the right way to define list ... but it works sort of
> incidentally because Scheme permits "rest" parameters which gather
> multiple arguments into a list.   
> 
> (define (list . x) x) also is equivalent and the syntax makes clear
> that x is intended to be a rest parameter.
> 
> 
> (lambda v v) is different from (lambda (v) v).  The unadorned v in the
> 1st indicates that v is a single rest parameter which will gather all
> the arguments into a list.  The parentheses in the 2nd indicate that v
> is a normal parameter which will take on a single value [which may be
> a deliberately passed list].
> 
> -> ((lambda v v) 1 2 3) 
>     => '(1 2 3)
> 
> -> ((lambda (v) v) 1 2 3) 
>     => #<procedure>: arity mismatch
> 
> 
> Rest parameters may be combined with required parameters as in 
> (lambda (x . v) ... )  which is different from (lambda (x v) ... ).
> The dot in the parameter 1st indicates that v is a rest parameter.  In
> the 2nd, both x and v are normal parameters.
> 
> -> ((lambda (x . v) v) 1 2 3) 
>     => '(2 3)
> 
> -> ((lambda (x . v) x) 1 2 3) 
>     => 1
> 
> -> ((lambda (x v) v) 1 2 3) 
>     => #<procedure>: arity mismatch
> 
> -> ((lambda (x v) v) 1 2) 
>     => 2
> 
> 
> A function can have only a single rest parameter [or none]. 
> 
> 
> Hope this helps,
> George

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to