Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added 20 characters in body; edited title
Source Link
Will Ness
  • 71.6k
  • 10
  • 105
  • 192

Non-Recursive list List function with Y Combinatorcombinator does no recursion, why?

Note: This is kind of homework, kind of not -- the end goal is to have a function that produces a powerset of a set of numbers supplied to the function as a list of numbers. I ahehave a recursive version of the function but I now need to find some ways of replacing each implicitlyexplicitly recursive function in the solution I have (appendappend, mapmmapm etc.) with an equivalent lambda-only expression. 

As such, I am starting with smaller problems and hope to combine them all to write a full function. I've managed to come up with a non-recursive factorial function using pure-lambda (y-combY combinator) but I am now trying to come up with a nice function that squares every number in a list -- trying to solve smaller problems before jumping up to a multiply-recursive function.:

(define (sqrlist numlist) (((lambda (f) ((lambda (x) (x x)) (lambda (g) (f (lambda (x) ((g g) x)))))) (lambda (f) (lambda (x) (cons (sqr (first x)) (rest x))))) numlist)) 

The code above doesn't recurse, despite the presence of the y-combinatorY combinator before it -- I'm obviously having some issues passing the proper parameters to the functions within -- any ideas?

Non-Recursive list function with Y Combinator

Note: This is kind of homework, kind of not - the end goal is to have a function that produces a powerset of a set of numbers supplied to the function as a list of numbers. I ahe a recursive version of the function but I now need to find some ways of replacing each implicitly recursive function in the solution I have (append, mapm etc.) with an equivalent lambda-only expression. As such, I am starting with smaller problems and hope to combine them all to write a full function. I've managed to come up with a non-recursive factorial function using pure-lambda (y-comb) but I am now trying to come up with a nice function that squares every number in a list - trying to solve smaller problems before jumping up to a multiply-recursive function.

(define (sqrlist numlist) (((lambda (f) ((lambda (x) (x x)) (lambda (g) (f (lambda (x) ((g g) x)))))) (lambda (f) (lambda (x) (cons (sqr (first x)) (rest x)))))numlist)) 

The code above doesn't recurse, despite the presence of the y-combinator before it - I'm obviously having some issues passing the proper parameters to the functions within - any ideas?

List function with Y combinator does no recursion, why?

Note: This is kind of homework, kind of not -- the end goal is to have a function that produces a powerset of a set of numbers supplied to the function as a list of numbers. I have a recursive version of the function but I now need to find some ways of replacing each explicitly recursive function in the solution I have (append, mapm etc.) with an equivalent lambda-only expression. 

As such, I am starting with smaller problems and hope to combine them all to write a full function. I've managed to come up with a non-recursive factorial function using pure-lambda (Y combinator) but I am now trying to come up with a nice function that squares every number in a list -- trying to solve smaller problems before jumping up to a multiply-recursive function:

(define (sqrlist numlist) (((lambda (f) ((lambda (x) (x x)) (lambda (g) (f (lambda (x) ((g g) x)))))) (lambda (f) (lambda (x) (cons (sqr (first x)) (rest x))))) numlist)) 

The code above doesn't recurse, despite the presence of the Y combinator before it -- I'm obviously having some issues passing the proper parameters to the functions within -- any ideas?

edited tags
Link
Greg Hewgill
  • 1.0m
  • 192
  • 1.2k
  • 1.3k
Source Link
David
  • 113
  • 3
  • 8

Non-Recursive list function with Y Combinator

Note: This is kind of homework, kind of not - the end goal is to have a function that produces a powerset of a set of numbers supplied to the function as a list of numbers. I ahe a recursive version of the function but I now need to find some ways of replacing each implicitly recursive function in the solution I have (append, mapm etc.) with an equivalent lambda-only expression. As such, I am starting with smaller problems and hope to combine them all to write a full function. I've managed to come up with a non-recursive factorial function using pure-lambda (y-comb) but I am now trying to come up with a nice function that squares every number in a list - trying to solve smaller problems before jumping up to a multiply-recursive function.

(define (sqrlist numlist) (((lambda (f) ((lambda (x) (x x)) (lambda (g) (f (lambda (x) ((g g) x)))))) (lambda (f) (lambda (x) (cons (sqr (first x)) (rest x)))))numlist)) 

The code above doesn't recurse, despite the presence of the y-combinator before it - I'm obviously having some issues passing the proper parameters to the functions within - any ideas?