This worked!  Thanks

On Fri, May 10, 2019 at 10:12 AM Taylor R Campbell <campb...@mumble.net>
wrote:

> > Date: Fri, 10 May 2019 01:28:15 -0400
> > From: Nicholas Papadonis <nick.papadonis...@gmail.com>
> >
> > Does anyone know the proper code for a Y-combinator in Scheme that takes
> an
> > additional argument?  I tried the following solutions.  The non-tail
> > recursive implementation works, however the tail recursive implementaiton
> > fails.  Appreciate any guidance here.  Thanks
> >
> > ;; Y-combinator
> > (define Y
> >   (lambda (f)
> >       ((lambda (x) (f (delay (x x))))
> >        (lambda (x) (f (delay (x x)))))))
> > ;Value: y
> > ;; end Y-combinator
> >
> > ;; non-tail recursive, works
> > ((Y (lambda (r)
> >       (lambda (x)
> >         (if (< x 2)
> >             1
> >             (* x ((force r) (- x 1)))))))
> >    5)
> > ;Value: 120
> >
> > ;; Tail reclusive implication, fails.
> > ((Y (lambda (r)
> >       (lambda (x acc)
> >         (if (< x 2)
> >             acc
> >             (r (- x 1) (* x acc))))))
> >    5 1)
> > ;The object #[promise 18] is not applicable.
>
> Try (force r) instead of r.
>
_______________________________________________
MIT-Scheme-users mailing list
MIT-Scheme-users@gnu.org
https://lists.gnu.org/mailman/listinfo/mit-scheme-users

Reply via email to