racket

List function with Y combinator does no recursion, why?

半世苍凉 提交于 2020-12-31 06:56:34
问题 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

How do foldl and foldr work, broken down in an example?

房东的猫 提交于 2020-12-30 08:44:34
问题 Okay, I am new with scheme/racket/lisp. I am practicing creating my own functions, syntax, and recursion, so I want to make my own foldl and foldr functions that do exactly what the predefined versions do. I can't do it because I just don't understand how these functions work. I have seen similar questions on here but I still don't get it. Some examples broken down would help! Here is my (incorrect) process: (foldl - 0 '(1 2 3 4)) I do 0 -(4-3-2-1) and get 2 which is the right answer (foldl -

How do foldl and foldr work, broken down in an example?

谁都会走 提交于 2020-12-30 08:44:12
问题 Okay, I am new with scheme/racket/lisp. I am practicing creating my own functions, syntax, and recursion, so I want to make my own foldl and foldr functions that do exactly what the predefined versions do. I can't do it because I just don't understand how these functions work. I have seen similar questions on here but I still don't get it. Some examples broken down would help! Here is my (incorrect) process: (foldl - 0 '(1 2 3 4)) I do 0 -(4-3-2-1) and get 2 which is the right answer (foldl -

How do I get a subtree by index?

元气小坏坏 提交于 2020-12-12 11:52:10
问题 Suppose I have the following tree: In my program, this tree is represented using a list: '(+ (* 5 6) (sqrt 3)) . How do I get a subtree by its index? The index should start from 0 and be depth-first. In the picture above, I have labelled all the nodes with their index to show this. For example: (define tree '(+ (* 5 6) (sqrt 3))) (subtree tree 0) ; Returns: '(+ (* 5 6) (sqrt 3))) (subtree tree 1) ; Returns: '(* 5 6) (subtree tree 2) ; Returns: 5 (subtree tree 3) ; Returns: 6 (subtree tree 4)

How do I get a subtree by index?

生来就可爱ヽ(ⅴ<●) 提交于 2020-12-12 11:51:45
问题 Suppose I have the following tree: In my program, this tree is represented using a list: '(+ (* 5 6) (sqrt 3)) . How do I get a subtree by its index? The index should start from 0 and be depth-first. In the picture above, I have labelled all the nodes with their index to show this. For example: (define tree '(+ (* 5 6) (sqrt 3))) (subtree tree 0) ; Returns: '(+ (* 5 6) (sqrt 3))) (subtree tree 1) ; Returns: '(* 5 6) (subtree tree 2) ; Returns: 5 (subtree tree 3) ; Returns: 6 (subtree tree 4)

How do I get a subtree by index?

故事扮演 提交于 2020-12-12 11:51:06
问题 Suppose I have the following tree: In my program, this tree is represented using a list: '(+ (* 5 6) (sqrt 3)) . How do I get a subtree by its index? The index should start from 0 and be depth-first. In the picture above, I have labelled all the nodes with their index to show this. For example: (define tree '(+ (* 5 6) (sqrt 3))) (subtree tree 0) ; Returns: '(+ (* 5 6) (sqrt 3))) (subtree tree 1) ; Returns: '(* 5 6) (subtree tree 2) ; Returns: 5 (subtree tree 3) ; Returns: 6 (subtree tree 4)