racket

Typed racket require module repeated evaluation

こ雲淡風輕ζ 提交于 2021-01-05 07:22:46
问题 This is a follow-on to this answer to this question. When this code is saved to a file and run from the command line, it prints 13 three times. Twice I can understand, but three times? Why? When I run it from racket-mode in emacs it prints 13 five times! And when I run it in DrRacket it prints 13 seven times! The behaviour is also different in vanilla Racket? Changing #lang typed/racket to #lang racket prints 13 once from the command line, twice from emacs and three times from DrRacket. What

Why does (require (for-syntax 'm)) execute expressions in the required module 3 times in DrRacket?

混江龙づ霸主 提交于 2021-01-04 07:38:05
问题 I don't know how to explain the following behavior in DrRacket's interactions window. I think the output should be only one "hello", since the module m should be instantiated once in this case. But actually "hello" is printed 3 times. > (module m racket (printf "hello\n")) > (module n racket (require (for-syntax 'm))) hello hello hello > The same behavior also exists if I write this example in DrRacket's definitions window and run it. #lang racket (module m racket (printf "hello\n")) (module

Get a subtree by breadth-first index using continuation-passing style

落爺英雄遲暮 提交于 2021-01-04 06:38:07
问题 This question is a follow-up on How do I get a subtree by index?. That question deals with depth-first indexing (for which I have provided a depth-first continuation-passing style solution). This question here is about breadth-first indexing, and specifically about solving the problem using continuation-passing style (CPS). Suppose I have a tree that represents '(+ (* 5 6) (sqrt 3)) : The index of nodes starts from 0 at the root, and is breadth-first. In the picture above, I have labelled all

Get a subtree by breadth-first index using continuation-passing style

 ̄綄美尐妖づ 提交于 2021-01-04 06:37:10
问题 This question is a follow-up on How do I get a subtree by index?. That question deals with depth-first indexing (for which I have provided a depth-first continuation-passing style solution). This question here is about breadth-first indexing, and specifically about solving the problem using continuation-passing style (CPS). Suppose I have a tree that represents '(+ (* 5 6) (sqrt 3)) : The index of nodes starts from 0 at the root, and is breadth-first. In the picture above, I have labelled all

Powerset of a list using abstract list functions

£可爱£侵袭症+ 提交于 2021-01-04 05:51:25
问题 Is it possible to make a racket function to return powerset of a given list ? Constraints- without explicit recursion use abstract list functions code contained in 2 lines (actual requirement) For eg: (powerset '(1 2)) '((1 2) (1) (2) ()) in any order. The other question I found still uses explicit recursion. My workflow: Taking (powerset '(a b c)) as an example, First get a list of whole numbers up to (expt 2 (length list)) ;'(0 1 2 3 4 5 6 7) Convert them into their respective binary form 2

How do I replace part of a tree with another tree at the specified index?

帅比萌擦擦* 提交于 2021-01-04 05:42:38
问题 Suppose I have two trees: Tree A — '(+ (* 5 6) (sqrt 3)) : Tree B — '(- 4 2) : Goal: replace one of tree A's subtrees with tree B at a specified tree A index position. The index position starts at 0 at the root node and is depth-first. In the figure for tree A above, I have labelled all the nodes with their index to show this. For example, (replace-subtree treeA 4 treeB) replaces the subtree at index 4 in tree A with tree B, resulting in the tree (+ (* 5 6) (- 4 2)) : How do I implement

How do I replace part of a tree with another tree at the specified index?

不问归期 提交于 2021-01-04 05:42:05
问题 Suppose I have two trees: Tree A — '(+ (* 5 6) (sqrt 3)) : Tree B — '(- 4 2) : Goal: replace one of tree A's subtrees with tree B at a specified tree A index position. The index position starts at 0 at the root node and is depth-first. In the figure for tree A above, I have labelled all the nodes with their index to show this. For example, (replace-subtree treeA 4 treeB) replaces the subtree at index 4 in tree A with tree B, resulting in the tree (+ (* 5 6) (- 4 2)) : How do I implement

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

北城余情 提交于 2021-01-04 02:10:01
问题 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

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