Do you have to use display to output stuff using r6rs?
Background: I am new to scheme, and am using DrScheme to write my programs.
The following program outputs 12345 when I run the program as r5rs:
12345
However the following program outputs nothing (it's an r6rs program):
#!r6rs
(import (rnrs))
12345
That being said, I can get it to output 12345 by doing this:
开发者_StackOverflow社区#!r6rs
(import (rnrs))
(display 1235)
Is that something new with r6rs, where output only occurs when specifically specified using display
? Or am I just doing something else wrong
This is a subtle issue that you're seeing here. In PLT, the preferred mode of operation is to write code in a module, where each module has a specification of the language it is written it. Usually, the default language is #lang scheme
(and #!
is short for #lang
). In this language, the behavior is for all toplevel non-definition expressions to display their values (unless they're void -- as in the result of most side-effects). But the #lang r5rs
and #lang r6rs
don't do the same -- so these toplevel expressions are evaluated but never displayed.
The reason you did see some output with the R5RS language is that you didn't use it as a "module" (as in #lang r5rs
), but instead used the specific R5RS "language level". This language level is more compatible to the R5RS, but for various subtle reasons this is not a good idea in general. Using #lang
is therefore generally better, and if you want to save yourself some additional redundant headaches, it'll be easier if you stick with #lang scheme
for now, and worry about standards later. (But YMMV, of course.)
精彩评论