On Tue, Sep 6, 2016 at 7:30 PM, Sanjeev Sharma <throw...@gmail.com> wrote:

> 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.
>
>
>From your description, the arity mismatches are probably caused by the fact
that you're defining `subsets` as a variable arity function, but internally
the recursive uses assume that it takes a single list. Your code in the
original post was:

(define ss
  (lambda s
    (if (null? s)
      (list nil)
      (let ((rest (subsets (cdr s))))
        (append
         rest
         (map
          (lambda (x)
            (append (list (car s))
                    x))
          rest))))))


The `(lambda s ...)` is variable-arity, but when you call `ss` internally,
you're always passing a single list as the argument. If you want a
variable-arity version, the simplest way is to define it as a simple
wrapper around a recursive fixed-arity version. Alternatively, you could
use `apply` in your recursive calls, but I'd call that bad style.

-- 
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