scheme

Divisible Function Scheme

自闭症网瘾萝莉.ら 提交于 2019-12-12 04:18:43
问题 I'm trying to write a function that determines if a number is divisible by 2 or 3. From what i've read online there is already a Scheme predicate divisible? but it is not working for me. I've tried writing one myself, but I don't know how to write a predicate function. Is there any help I can get? Thanks! 回答1: The divisible? predicate can be expressed in terms of the remainder procedure, remember: a number n is divisible by x if the remainder of dividing n by x is zero. (define (divisible? n

.Dynamically changing the clock tick rate in big-bang

你离开我真会死。 提交于 2019-12-12 04:17:37
问题 The on-tick clause includes an option to change the clock tick rate. I have included my code to dynamically change the value depending on the world state value. The code is not working and I can't understand why. Another issue - how are world programs debugged? The "step" option doesn't work. ; physical constants (define HEIGHT 300) (define WIDTH 100) (define YDELTA 3) ; graphical constants (define BACKG (empty-scene WIDTH HEIGHT)) (define ROCKET (rectangle 5 30 "solid" "red")) (define ROCKET

SCHEME Mutable Functions

别来无恙 提交于 2019-12-12 03:52:51
问题 I've been self-teaching myself Scheme R5RS for the past few months and have just started learning about mutable functions. I've did a couple of functions like this, but seem to find my mistake for this one. (define (lst-functions) (let ((lst '())) (define (sum lst) (cond ((null? lst) 0) (else (+ (car lst) (sum (cdr lst)))))) (define (length? lst) (cond ((null? lst) 0) (else (+ 1 (length? (cdr lst)))))) (define (average) (/ (sum lst) (length? lst))) (define (insert x) (set! lst (cons x lst)))

Scheme:function assistance

有些话、适合烂在心里 提交于 2019-12-12 03:29:31
问题 i am fairly new to Scheme and,i was thinking of a way to cube every number in a given list recursively so far this is what i have: (define (cube-it-list lst) (cond [(empty? lst) empty] [else (cons (cube-it (first lst)) (cube-it-list (rest lst)))])) but every time I execute the program i get an error and i'm not sure why that is can anyone help or come up with a better more efficient way to do this. 回答1: The function looks fine, maybe the problem is in the cube-it procedure or in the way you

Scheme, search if a word is a part of list

允我心安 提交于 2019-12-12 03:27:13
问题 I did a program which is searching if an element is a part of the list, but it is not working with words My program: (define (element? xs lst) (cond ((null? lst) #f) ((eq? xs (car lst)) #t) (#t (element? x (cdr lst))))) examples: >(element? 'three (quote ((quote three) (quote four) (quote five)))) >,=> #f but i need #t please help. 回答1: When Scheme encounters a (quote x) or it's short form 'x x is the result unevaluated. Thus (quote ((quote three) (quote four) (quote five))) becomes the list

Starting SublimeREPL for Scheme gives OSError(2, 'No such file or directory')

一笑奈何 提交于 2019-12-12 03:08:59
问题 I've been trying to use SublimeREPL to run an interactive interpreter of Scheme, but I keep getting the error message "OSError(2, 'No such file or directory')". I know it's likely a file path issue in Main.sublime-menu, but I just can't seem to figure it out. Not sure if I'm missing something obvious or what. Any help would be appreciated! Here is the config file that I have in SublimeREPL/config/Scheme (unchanged since install): [ { "id": "tools", "children": [{ "caption": "SublimeREPL",

Recursive sublist? function

你。 提交于 2019-12-12 03:07:12
问题 I can't seem to figure how to write a correct uscheme (A derivative of MIT Scheme) function that will return boolean whether a list contains a smaller list. I wrote this. (define sublist? (xs ys) (if (= xs '()) #t (if (= ys '()) #f (if (= (car xs) (car ys)) (sublist? (cdr xs) (cdr ys)) (sublist? xs (cdr ys)) ) ) ) ) It passes most of my test cases except this one test case. (sublist? '(a b c) '(1 2 a 3 b 4 c 5 6)) ;; this returns true while it's supposed to return false Test case requires

Remove subsequence function (deep recursion) in Scheme using CPS

核能气质少年 提交于 2019-12-12 02:55:37
问题 removesub* takes a list of atoms and a general list. The first list is a subsequence of the second list. The method should return the second list with the first occurence of the subsequence removed. So, if the first list is '(a b c), the first a if the second list is removed, the first b that appears after the removed a is removed, and the first c that appears after the removed b is removed - no matter how deep the atoms are nested. (removesub* '(a b) '(w (x b) ((a) ((y z))) b)) Expected

(SCHEME): Dividing a bigint into tens, hundreds, ect. And into a list that contains english

纵饮孤独 提交于 2019-12-12 02:49:30
问题 So I'm having a hard time trying to write this program. The scope is a program that will take a large number, (say 1,000,000) and split it into its digits (ie 1,500,310 -> 1 million 500 thousand 3 hundred 1 ten 0 one). #lang r5rs (define (three_names x) (let loop ((x x) (myList '())) (if (< x 10) (cons x myList) (loop (quotient x 10) (cons (remainder x 10) myList))))) I've gotten it so that it will loop and return these values each into a list with some help from stackoverflow. (i.e. this

find sum of the squares of the digits of a number in scheme

a 夏天 提交于 2019-12-12 02:29:31
问题 I need to write a function in scheme which calculates the sum of square digits. ex - (sum-of-digits 130) > 10 This is my function. (define (sum-of-digits x) (if (= x 0) 0 (+ (modulo x 10) (sum-of-digits (/ (- x (modulo x 10)) 10))))) it doesn't work for some numbers. When I entered (sum-of-digits 130) , it returns 4. How can i fix this ? Also I need to use this function to find the stop numbers which are 0,1,4,16,20,37,42,58,89,145 ex :- (stop? 42)  #t (stop? 31)  #f How can I do this using