scheme

How are these nested vectors connected?

对着背影说爱祢 提交于 2021-02-09 17:47:09
问题 I've written a piece of code, which creates a vector 'scoreboard' that contains 3 seperate vectors of size 3, all containing the symbol ? at all indices 0-2. When i now execute a 'vector-set!' on the first vector of scoreboard, to change its first element to a 'X, vectors 2 and 3 will change too. How does this occur? (define scoreboard (make-vector 3 (make-vector 3 '?))) (define (display-scoreboard) (display (vector-ref scoreboard 0)) (newline) (display (vector-ref scoreboard 1)) (newline)

How to make executable File using Gambit

孤人 提交于 2021-02-08 09:55:56
问题 I wrote this Scheme source file on notepad. I have gambit scheme installed. (define hello-world (lambda () (begin (write ‘Hello-World) (newline) (hello-world)))) I use windows command line. i type in 'gsc hello.scm' in the command line. It spits out a file on my desktop called "hello.o2". I want to see "Hello-World" pop up on my command line. For example, when I compile stuff in c++ it gives me a file called a.exe and I am able to observe it on the command line. how can I do this with the

What is the difference between an “interned” and an “uninterned” symbol

懵懂的女人 提交于 2021-02-07 14:22:25
问题 What is the difference between an "interned" and an "uninterned" symbol. Is it only Racket that has uninterned symbols or do other dialects of scheme or lisp have them? 回答1: Interned symbols are eq? if and only if they have the same name. Uninterned symbols are not eq? to any other symbol, so they are a kind of unique token with an attached string. Interned symbols are the kind that are produced by the default reader. Uninterned symbols can be used as identifiers when generating code in a

What is the difference between an “interned” and an “uninterned” symbol

北城余情 提交于 2021-02-07 14:21:49
问题 What is the difference between an "interned" and an "uninterned" symbol. Is it only Racket that has uninterned symbols or do other dialects of scheme or lisp have them? 回答1: Interned symbols are eq? if and only if they have the same name. Uninterned symbols are not eq? to any other symbol, so they are a kind of unique token with an attached string. Interned symbols are the kind that are produced by the default reader. Uninterned symbols can be used as identifiers when generating code in a

How to implement a try-catch block in scheme?

和自甴很熟 提交于 2021-02-07 12:15:16
问题 I'm trying to implement a try-catch block in scheme using (call-cc) method but i'm not sure how it can be used for that. I could not find any example. And found examples contains just error-handling but what i want to do is: if an error occurred, the scheme program has to give a message to user (via display for-example) without suspending the program. Is that possible? 回答1: Since you want to catch all errors, such as ones raised by both raise and raise-continuable you'd need both an exception

How to implement a try-catch block in scheme?

岁酱吖の 提交于 2021-02-07 12:14:26
问题 I'm trying to implement a try-catch block in scheme using (call-cc) method but i'm not sure how it can be used for that. I could not find any example. And found examples contains just error-handling but what i want to do is: if an error occurred, the scheme program has to give a message to user (via display for-example) without suspending the program. Is that possible? 回答1: Since you want to catch all errors, such as ones raised by both raise and raise-continuable you'd need both an exception

Commenting code in Scheme

巧了我就是萌 提交于 2021-02-06 07:21:05
问题 I am looking at some code in Scheme from Festival and cannot seem to figure out the comments. Currently, I can see ; , ;; and ;;; used to indicate comment lines. Other sources on the web indicate that some of the above maybe ways to indicate multi-line comments. My questions are: What is the difference between ; , ;; and ;;; for commenting? When is one to be used over the other? Is there any other, IMO saner, way to comment code in Scheme ? 回答1: The comment character is ; and anything

Commenting code in Scheme

﹥>﹥吖頭↗ 提交于 2021-02-06 07:18:52
问题 I am looking at some code in Scheme from Festival and cannot seem to figure out the comments. Currently, I can see ; , ;; and ;;; used to indicate comment lines. Other sources on the web indicate that some of the above maybe ways to indicate multi-line comments. My questions are: What is the difference between ; , ;; and ;;; for commenting? When is one to be used over the other? Is there any other, IMO saner, way to comment code in Scheme ? 回答1: The comment character is ; and anything

Commenting code in Scheme

萝らか妹 提交于 2021-02-06 07:18:09
问题 I am looking at some code in Scheme from Festival and cannot seem to figure out the comments. Currently, I can see ; , ;; and ;;; used to indicate comment lines. Other sources on the web indicate that some of the above maybe ways to indicate multi-line comments. My questions are: What is the difference between ; , ;; and ;;; for commenting? When is one to be used over the other? Is there any other, IMO saner, way to comment code in Scheme ? 回答1: The comment character is ; and anything

How can write a program in scheme to find factors of a list of numbers

匆匆过客 提交于 2021-02-05 12:25:33
问题 This is the code for a single integer, how can it extends to list of function? (define (factors n) (define (*factors d) (cond ((> d n) (list)) ((= (modulo n d) 0) (cons d (*factors (+ d 1)))) (else (*factors (+ d 1))))) (*factors 1)) (display (factors 1111111)) (newline) 回答1: You can use for-each to iterate over a list. (define (factors n) (define (*factors d) (cond ((> d n) (list)) ((= (modulo n d) 0) (cons d (*factors (+ d 1)))) (else (*factors (+ d 1))))) (*factors 1)) (define arbitarily