tags:

views:

31

answers:

1

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:

#!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

+1  A: 

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.)

Eli Barzilay