scheme

Is it possible to generate (quote (quote var)) or ''var dynamically?

╄→гoц情女王★ 提交于 2019-12-23 05:34:09
问题 In question Using AND with the apply function in Scheme , I proposed an solution to apply "and" onto a list of atoms (i.e. s-exp which is neither null, nor pair.) in PLT-Scheme 372. Welcome to DrScheme, version 372 [3m]. Language: Textual (MzScheme, includes R5RS). > (eval (cons 'and (list ''#f ''#f ''#t))) #f > (eval (cons 'and (list ''a ''b ''c))) c But right after that I realized that: it's not easy to generate (quote (quote var)) or ''var dynamically. To be specific, the following code

Scheme procedure to compute the nth repeated application of a function?

坚强是说给别人听的谎言 提交于 2019-12-23 03:34:12
问题 Is anyone familiar with this? Write a procedure that takes as inputs a procedure that computes f and a positive integer n and returns the procedure that computes the nth repeated application of f. The procedure should be able to be used as follows: ((repeated square 2) 5) 625 I know that the following code I've created for the composition of functions will help make the solution simpler, but I'm not sure where to go from here: (define (compose f g) (lambda (x) (f (g x)))) 回答1: Well, you

Solving a puzzle in Racket

喜夏-厌秋 提交于 2019-12-23 03:22:40
问题 I tried to solve this puzzle https://puzzling.stackexchange.com/questions/40094/who-committed-the-crime using Racket. A crime has been carried out by one person, there are 5 suspects. Each suspect is asked under polygraph who they think committed the crime. Their answers are as follows: Terry : It wasn't Carl, It was Steve Steve : It wasn't Matt, It wasn't Carl Matt : It was Carl, It wasn't Terry Ben : It was Matt, It was Steve Carl : It was Ben, It wasn't Terry The polygraph showed that each

Scheme function that returns the odd-numbered elements from a list in reverse

淺唱寂寞╮ 提交于 2019-12-23 03:21:30
问题 I have to create a recursive Scheme function for my programming class that will take all the odd-numbered elements of a list, and then return them in reversed order. I have a function for reversing a list, and another function for getting the odd-numbered elements, but can't figure out how to combine the two into a new function, as they both are recursive. It has to be one function that doesn't call any functions other than itself. It can not call odd or reverse , and it has to have the same

Scheme function that returns the odd-numbered elements from a list in reverse

人盡茶涼 提交于 2019-12-23 03:21:28
问题 I have to create a recursive Scheme function for my programming class that will take all the odd-numbered elements of a list, and then return them in reversed order. I have a function for reversing a list, and another function for getting the odd-numbered elements, but can't figure out how to combine the two into a new function, as they both are recursive. It has to be one function that doesn't call any functions other than itself. It can not call odd or reverse , and it has to have the same

How to print a string in backward, in scheme?

被刻印的时光 ゝ 提交于 2019-12-22 23:11:23
问题 I know if I write my scheme code in the following way and type in (word ‘(a b c)), it will out put the list in the same order. Could you please tell me if there was a way I can print it out in opposite order. Ex- (list ‘c ‘b ‘a). it needs to be the user's input I print out in opposite order. So, I can't call it (reverse '(a b c)). since the user input can be something like '(x y z). Thanks a lot. (define(word x ) (if(null? x) x (cons(car x)(word (cdr x))))) (word '(a b c)) (list 'a 'b 'c) 回答1

How to print a string in backward, in scheme?

不羁的心 提交于 2019-12-22 23:11:23
问题 I know if I write my scheme code in the following way and type in (word ‘(a b c)), it will out put the list in the same order. Could you please tell me if there was a way I can print it out in opposite order. Ex- (list ‘c ‘b ‘a). it needs to be the user's input I print out in opposite order. So, I can't call it (reverse '(a b c)). since the user input can be something like '(x y z). Thanks a lot. (define(word x ) (if(null? x) x (cons(car x)(word (cdr x))))) (word '(a b c)) (list 'a 'b 'c) 回答1

Scheme function [closed]

倖福魔咒の 提交于 2019-12-22 18:53:42
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I am trying to interpret what this scheme function does: (define (y s lis) (cond ((null? lis) '() ) ((equal? s (car lis)) lis) (else (y s (cdr lis))))) It runs but I am not exactly sure what it is doing or trying to do. Does it need a list to sort or something? I am using DrRacket to run it. I have never seen

Binary trees in scheme

三世轮回 提交于 2019-12-22 18:46:10
问题 How would I count how many nodes a tree has? ;;; A Binary is one of: ;;; - Number ;;; - (make-node BT BT) (define-struct node (left right)) (define tree1 (make-node (make-node 10 9) (make-node 3 (make-node 1 5)))) (define (how-many? nd) (cond [(number? nd)....] [(node? n) (..... (how-many? (node-left nd)) (how-many? (node-right nd)))])) so for tree1 I should get (check-expect (how-many? tree1) 5) I think I got the template right. If it's a number, you should return 1 . But if it's a node ,

Towers of Hanoi in Scheme (recursive)

妖精的绣舞 提交于 2019-12-22 18:30:20
问题 I wrote the following code in scheme today, but the evaluation is wrong. Please don't tell me I suck at programming, I understand that this is a classic recursion problem, but I am having trouble with it: (define (towers-of-hanoi n source temp dest) (if (= n 1) (begin (display "Move the disk from ") (display source) (display " to " ) (display dest) (newline)) (begin (towers-of-hanoi (- n 1) source temp dest) (display "Move the disk from ") (display source) (display " to ") (display dest)