scheme

Generating powerset in one function, no explicit recursion, and using only simplest primitives in Racket

微笑、不失礼 提交于 2021-01-04 01:58:54
问题 Note: this is a bonus for homework, but I have spent way too long on trying things to no avail. Help is much appreciated, but not necessary I suppose. Premise: generate a powerset for a list of numbers, but without using any helpers, explicit recursion, looping, or functions/constants other than cons , first , rest , empty? , empty , else , lambda , and cond , while using only one define on the language level Intermediate Student with Lambda . The order of the powerset does not matter. What I

List function with Y combinator does no recursion, why?

耗尽温柔 提交于 2020-12-31 07:00:17
问题 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

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 -

What is the difference between map and apply in scheme?

流过昼夜 提交于 2020-12-29 02:49:50
问题 I am trying to learn Scheme and I am having a hard time understanding the difference between map and apply . As I understand, map applies the function to each element of the list, and apply applies something to the arguments of a procedure. Can they be used interchangeably? 回答1: They are not the same! Their names can actually help remember which does what. map will take as argument one procedure and one or more lists. The procedure will be called once for each position of the lists, using as

What is the difference between map and apply in scheme?

情到浓时终转凉″ 提交于 2020-12-29 02:49:10
问题 I am trying to learn Scheme and I am having a hard time understanding the difference between map and apply . As I understand, map applies the function to each element of the list, and apply applies something to the arguments of a procedure. Can they be used interchangeably? 回答1: They are not the same! Their names can actually help remember which does what. map will take as argument one procedure and one or more lists. The procedure will be called once for each position of the lists, using as

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)