r5rs

DrRacket, R5RS and the error procedure

不想你离开。 提交于 2021-02-19 03:50:05
问题 I love DrRacket IDE, but currently I'm building a pet project where I would like to be independent from it, meaning i'm commited to use only R5RS standard procedures. The thing is, in DrRacket there's this procedure called "error" which i would like to continue using but I can't find it in the Standards. What i would like to know is if there's a way to emulate that "error" procedure using only the Standards procedures so that the code is portable between different implementations of Scheme. I

How are these nested vectors connected?

ぃ、小莉子 提交于 2021-02-09 17:49:04
问题 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 are these nested vectors connected?

自作多情 提交于 2021-02-09 17:47:17
问题 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 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 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)

Sorting list of lists by their first element in scheme

北城以北 提交于 2021-01-27 21:22:52
问题 I'm working on sorting a list of lists by their first element for example (sort (list '(2 1 6 7) '(4 3 1 2 4 5) '(1 1)))) expected output => ('(1 1) '(2 1 6 7) '(4 3 1 2 4 5)) The algorithm I used is bubble sort. And I modified it to deal with lists. However, the code doesn't compile. The error is mcar: contract violation expected: mpair? given: 4 Can someone correct my code and explain it. Thank you (define (bubble L) (if (null? (cdr L)) L (if (< (car (car L)) (car (cadr L))) (list (car L)

Encoding Huffman Tree Scheme [closed]

萝らか妹 提交于 2020-04-16 02:16:09
问题 Closed. This question needs debugging details. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 days ago . I am trying to write a function, (codeWords t) , which traverses a Huffman tree (adds #\0 when it goes left, adds #\1 when it goes right...) and returns these values in pairs of the symbol at a leaf along with its associated encoding as a string over the characters #\0 and #\1 . Similar to what this or

How to get system date in R5Rs in Scheme/DrRacket

守給你的承諾、 提交于 2020-01-07 06:46:21
问题 In DrRacket IDE, I was able to get the system date in the following manner when the language setting was 'Swindle': (define currentMonth 0) (let ((date (seconds->date (current-seconds)))) (set! currentMonth (date-month date)) ) Now, I need to do the same in R5Rs, but not sure how to. May I please seek your advise/help on this.. Thank you! 回答1: There is no date-time support in R5RS. The procedures current-seconds , seconds->date and date-month should be available in the R5RS implementation of

What's the return value of `define` in Scheme?

断了今生、忘了曾经 提交于 2020-01-04 13:39:59
问题 I'm curious about the return value of define in Scheme. So I wrote the following lines in Racket #lang r5rs (display (define a 3)) And get the error define: not allowed in an expression context in: (define a 3) I have 2 questions about this: Does it mean that define has no return value? According to R5RS, define is not an expression. It's a program structure. Is it true that only expressions have return values, and other forms don't? 回答1: "If a tree falls in a forest and no one is around to

SCHEME - Writing my own append produces a weird result

半城伤御伤魂 提交于 2019-12-24 10:44:58
问题 I want to write my own append , for appending an element to an existing list . I've written the following : (define (appendElem llist elem) (if (null? llist) elem (cons (car llist) (appendElem (cdr llist) elem)))) But when I do this : (appendElem (list 1 2 30) 11) I get : (1 2 30 . 11) So the question is , why (1 2 30 . 11) and not (1 2 30 11) ? Thanks EDIT: Fixed : (define (appendElem llist elem) (if (null? llist) (list elem) (cons (car llist) (appendElem (cdr llist) elem)))) 回答1: Think