racket

How to change the order of the contents of a list in racket?

删除回忆录丶 提交于 2020-06-27 16:57:17
问题 I'm a beginner in racket and am learning how lists work. I have to create a function that takes in a count variable and a list and produces the same list but with the first element cycled to the end of the list "count" number of times. My code works for even numbered lists, like calling the function 2 '(1 2 3 4), which results in a list '(3 4 1 2), but does not work for odd numbered lists, like calling 2 '(1 2 3), which should result in '(3 1 2) (define (cycleN count aList) (cond [(empty?

defining macro-generated macros that take in variable number of arguments

混江龙づ霸主 提交于 2020-06-27 09:11:00
问题 I am trying to write a macro-generating macro, where the macro it generates takes a variable number of arguments. I am wondering if there is a way to make the following code work: (define-syntax-rule (greet name) (define-syntax-rule (name args ...) (printf "hello ~a~n" (list args ...)))) Right now it says "no pattern variables before ellipsis in template in: ... " If I take the inner define-syntax-rule by itself it works fine, so why doesn't it work when it's being generated by another macro?

defining macro-generated macros that take in variable number of arguments

痴心易碎 提交于 2020-06-27 09:10:26
问题 I am trying to write a macro-generating macro, where the macro it generates takes a variable number of arguments. I am wondering if there is a way to make the following code work: (define-syntax-rule (greet name) (define-syntax-rule (name args ...) (printf "hello ~a~n" (list args ...)))) Right now it says "no pattern variables before ellipsis in template in: ... " If I take the inner define-syntax-rule by itself it works fine, so why doesn't it work when it's being generated by another macro?

How to recursively tile a defective chessboard in DrRacket

橙三吉。 提交于 2020-06-25 05:50:09
问题 I have a homework problem which is really messing with me right now, and I could use some help in how to implement it in DrRacket. I do not wish for code, just guidance, as I am very new to DrRacket. The assignment is to implement this phrase: "If n = 0, return the empty tiling (list of tile structs). Otherwise, place a tromino (L-shaped domino) in the center of the chessboard so that it covers the three quadrants of the chessboard that have no missing tile in them, and tile each of the

Update functions in Hash Table in Racket

懵懂的女人 提交于 2020-06-09 04:19:23
问题 I am a beginner in Racket and I am trying to updare a hash table using hash-update! where the value is a mutable set. Below are the code lines: (hash-update! hash key (curryr set-add! new_val) (mutable-set 1)) However I receive an error expected: set? given: #<void> argument position: 1st other arguments...: x: 2 where I tried 2 as the new_val Any suggestions ? 回答1: This is because the updater is supposed to be a function that takes a value as input and produces a new value output. Since the

How to apply first element of list to rest of list?

眉间皱痕 提交于 2020-05-16 02:14:16
问题 Why is: (apply (car (list 'xor)) '(#t #t)) application: not a procedure; expected a procedure that can be applied to arguments given: 'xor (apply (car (list (list 'xor))) '(#t #t)) application: not a procedure; expected a procedure that can be applied to arguments given: '(xor) (apply (car '(xor #t #t)) (cdr '(xor #t #t))) application: not a procedure; expected a procedure that can be applied to arguments given: 'xor How to apply first element of list to rest of list? 回答1: In your program,

How to apply first element of list to rest of list?

拈花ヽ惹草 提交于 2020-05-16 02:04:07
问题 Why is: (apply (car (list 'xor)) '(#t #t)) application: not a procedure; expected a procedure that can be applied to arguments given: 'xor (apply (car (list (list 'xor))) '(#t #t)) application: not a procedure; expected a procedure that can be applied to arguments given: '(xor) (apply (car '(xor #t #t)) (cdr '(xor #t #t))) application: not a procedure; expected a procedure that can be applied to arguments given: 'xor How to apply first element of list to rest of list? 回答1: In your program,

How to apply first element of list to rest of list?

喜你入骨 提交于 2020-05-16 02:03:06
问题 Why is: (apply (car (list 'xor)) '(#t #t)) application: not a procedure; expected a procedure that can be applied to arguments given: 'xor (apply (car (list (list 'xor))) '(#t #t)) application: not a procedure; expected a procedure that can be applied to arguments given: '(xor) (apply (car '(xor #t #t)) (cdr '(xor #t #t))) application: not a procedure; expected a procedure that can be applied to arguments given: 'xor How to apply first element of list to rest of list? 回答1: In your program,

Encode Huffman Tree Scheme

╄→гoц情女王★ 提交于 2020-04-21 05:27:19
问题 I am trying to build a function that encodes the following procedure at the bottom into 1's and 0's can anyone help find why I am getting the error message mpair given: 0. (define (symbols tree) (if (leaf? tree) (list (symbol-leaf tree)) (caddr tree))) (define (right-branch tree) (cadr tree)) (define (left-branch tree) (car tree)) (define (leaf? object) (eq? (car object) 'leaf)) (define (member? x set) (not (equal? (member x set) false))) (define (encode-branch symbol tree) (let ((left (left

Scheme Beginning Student, Function Body Extra Part

我怕爱的太早我们不能终老 提交于 2020-04-17 21:37:36
问题 I attempted to follow the solution provided in this question, but it simply didn't work. Essentially, my function works like so: (define (item-price size normal-addons premium-addons discount) (define price 0) (+ price (* normal-addon-cost normal-addons) (* premium-addon-cost premium-addons) size) (cond .. some conditions here [else price])) However, I am met with the following error: define: expected only one expression for the function body, but found 2 extra parts Now, I've tried wrapping