r6rs

Scheme pass-by-reference

血红的双手。 提交于 2021-02-17 21:51:10
问题 How can I pass a variable by reference in scheme? An example of the functionality I want: (define foo (lambda (&x) (set! x 5))) (define y 2) (foo y) (display y) ;outputs: 5 Also, is there a way to return by reference? 回答1: See http://community.schemewiki.org/?scheme-faq-language question "Is there a way to emulate call-by-reference?". In general I think that fights against scheme's functional nature so probably there is a better way to structure the program to make it more scheme-like. 回答2:

Can someone explain the concept of 'hygiene' to me (I'm a scheme programmer)?

若如初见. 提交于 2020-07-04 20:15:33
问题 So... I'm new to scheme r6rs, and am learning macros. Can somebody explain to me what is meant by 'hygiene'? Thanks in advance. 回答1: Hygiene is often used in the context of macros. A hygienic macro doesn't use variable names that can risk interfering with the code under expansion. Here is an example. Let's say we want to define the or special form with a macro. Intuitively, (or a b c ... d) would expand to something like (let ((tmp a)) (if tmp a (or b c ... d))) . (I am omitting the empty (or

How to change printing behaviour in DrRacket for R6RS to print results like with #lang racket

江枫思渺然 提交于 2019-12-30 11:09:10
问题 When I'm running a program in the IDE, version 5.3.5--2013-06-18(-/f), for #lang racket , eg. #lang racket (+ 4 5) (/ 10 2) When pressing Run > , the interaction window gets "9\n5\n" printed to the interactions window. The same version as R6RS #!r6rs (import (rnrs base)) (+ 4 5) (/ 10 2) It seems I get no output when pressing Run > when language is R6RS . Is there anywhere I can change this behavior, in Preferences perhaps? 来源: https://stackoverflow.com/questions/19624049/how-to-change

Is it possible to “extend” a function / lambda / macro in Scheme?

最后都变了- 提交于 2019-12-22 07:12:08
问题 For example: if I want the function equal? recognize my own type or record, can I add a new behavior of equal? ? without erasing or overwriting the old one? Or for example if I want to make the function "+" accept also string? 回答1: Rather than using import , a better solution is to keep track of the original function by let -binding it. It's also better to check that the type of the argument is a string, rather than that it is not a number. Using both of these approaches means that it's

Is it possible to “extend” a function / lambda / macro in Scheme?

本秂侑毒 提交于 2019-12-22 07:10:02
问题 For example: if I want the function equal? recognize my own type or record, can I add a new behavior of equal? ? without erasing or overwriting the old one? Or for example if I want to make the function "+" accept also string? 回答1: Rather than using import , a better solution is to keep track of the original function by let -binding it. It's also better to check that the type of the argument is a string, rather than that it is not a number. Using both of these approaches means that it's

Append string to existing textfile in IronScheme

一笑奈何 提交于 2019-12-10 18:19:14
问题 We are trying to construct a log file using IronScheme, and we have written a code for it using racket. It works fine in racket, but IronScheme throws an error. This is what we have so far: (define write-to-log (lambda(whatToWrite) (with-output-to-file "robot-log.txt" (lambda () (printf (string-append whatToWrite "\r\n" ))) #:exists 'append))) See how we use the "exists" optional parameter when using with-output-to-file. We are not sure how to make this optional parameter work with IronScheme

In R6RS Scheme, is there a way to get the current environment for use with eval?

a 夏天 提交于 2019-12-06 01:27:25
问题 Is there any way in R6RS Scheme to obtain the current environment and then pass it as the second argument to eval ? For example, what should the question marks be for the following expression to return 9? (let ((x 4) (y 5)) (eval '(+ x y) ???)) 回答1: No, there is no such thing in R6RS. Some rare implementations might support something like that, but in the overwhelming majority (including eval in other languages!) this cannot be done. The reason for that is simple: it breaks compilation, since

Is it possible to “extend” a function / lambda / macro in Scheme?

风格不统一 提交于 2019-12-05 11:34:11
For example: if I want the function equal? recognize my own type or record, can I add a new behavior of equal? ? without erasing or overwriting the old one? Or for example if I want to make the function "+" accept also string? Rather than using import , a better solution is to keep track of the original function by let -binding it. It's also better to check that the type of the argument is a string, rather than that it is not a number. Using both of these approaches means that it's possible to compose the technique. (define + (let ((old+ +)) (lambda args (if (string? (car args)) (apply string

In R6RS Scheme, is there a way to get the current environment for use with eval?

我怕爱的太早我们不能终老 提交于 2019-12-04 05:35:01
Is there any way in R6RS Scheme to obtain the current environment and then pass it as the second argument to eval ? For example, what should the question marks be for the following expression to return 9? (let ((x 4) (y 5)) (eval '(+ x y) ???)) No, there is no such thing in R6RS. Some rare implementations might support something like that, but in the overwhelming majority (including eval in other languages!) this cannot be done. The reason for that is simple: it breaks compilation, since it leads to making two functions distinguishable based on local names, and in some cases can also prohibit