Cannot load File in Scheme, (using Simply Scheme Book and PLT Scheme) - scheme

I am using PLT Scheme (DrScheme). I want to load a file that I got from here. To load the file, I go into PLT Scheme and in the interactions window (or the bottom window), I type (load "simply.scm") and then press enter. It gives me this error:
simply.scm:20:12: set!: cannot mutate module-required identifier in: number->string
I have no clue how to fix that, please assist...
Extra Info: I am learning out of the book Simply Scheme Introducing Computer Science by Brian Harvey and Matthew Wright
Also, the link takes a little long to load, but it does work, i think they have the files on a really old server, so that may be why.

Open DrScheme (or DrRacket as the newer version of the software is now called); from the Language menu select "Choose Language..." and make sure "Use the language declared in the source" is checked.
Then at the top of your file, put the following two header lines followed by whatever code you want from the book (I've chosen an example from the first chapter):
#lang racket
(require (planet dyoo/simply-scheme))
(define (pigl wd)
(if (member? (first wd) 'aeiou)
(word wd 'ay)
(pigl (word (butfirst wd) (first wd)))))
Then click run. This should allow you to also type expressions in the Interactions pane to evaluate them.
Alternatively, you can replace the two lines above with one:
#lang planet dyoo/simply-scheme
But then the Simply Scheme language is not enabled in the Interactions pane.
You can find the documentation for this DrScheme/Racket simply-scheme library by clicking on the 'docs' link at the URL provided by Chris.

You should use the Racket Simply Scheme module. The file you have linked to is not compatible with Racket.
More specifically, in Racket, you're not allowed to use set! to overwrite existing function bindings, which is what that file does. (Technically, it can potentially break other Scheme implementations also, so this isn't a "Racket quirk" or anything.)

Related

Little Schemer - IDE [duplicate]

I'm starting to read the Little Schemer and now instead of PLT Scheme we have Racket. I would like to know if Racket is suitable for doing the exercises in the book or do I need to get another true Scheme compiler. Before I forgot to tell you, my OS is Windows x64.
The book, language and paradigm is complex enough, I would love to avoid struggling with a compiler.
DrRacket is the (r)evolution of DrScheme; DrRacket will work perfectly for the exercises in "The Little Schemer". Just don't forget to:
In the Language dialog, choose "Use the language declared in the source"
Write #lang racket at the top of each file you create
Implement the atom? predicate in each file as explained at the very beginning of the book
If you're going to re-implement an existing procedure, do so in a separate tab or window, because trying to rewrite a procedure in the edit window will result in a duplicate definition for identifier error. If necessary, use several files for saving the procedure definitions
You really just need the atom? function. What’s described in the book's preface is essentially:
(define (atom? x)
(and (not (pair? x)) (not (null? x))))
As mentioned, it should satisfy this test:
(atom? '()) ;=> #f
Note that there is also a definition in Racklog that will not satisfy that test.
A more detailed discussion on atom? is here.
Despite the book's suggestion to implement add1 and sub1, Racket does already provide them.
BTW, I use Vim for editing Racket, but a few other editors are capable.
I have had the author of the book as a professor. He now uses Racket himself, but he uses Emacs as a text editor.
Racket/Scheme are interchangeable. You should be able to answer any exercise with it. Good luck.
Also, I recommend downloading Dr. Racket as your interpreter.

Racket language change & module problems

I'm trying to implement some of SICP graphic programs in Racket, but there are 2 problems:
When I need to use 'let' I can't use beginner language.
When I try to change language, or open new file while using "advanced" language, I get this error:
module: identifier already imported from a different source
error when I try to load image module by (require 2htdp/image).
What's going on? Also, are there better ways to train with images in Scheme?
It's not clear why you want to use 2htdp/image in the first place. A much more useful package to use would be Neil Van Dyke's SICP Support page, it provides a language with support for the book and includes the graphical language. That should be enough to solve both of your problems.
As Óscar mentions, you are better off with using #lang planet neil/sicp, However, if you want to import somethng that exports identical symbols you can prefix them:
(require (prefix-in hi: 2htdp/image))
Then all exported from that have prefix hi:, eg. (hi:circle 30 "outline" "red"). The colon isn't anything special. The prefix could have been xxx and it would be xxxcircle.
Also, you can only import the symbols you want:
; you only want circle and eclipse
(require (only-in 2htdp/image circle ellipse))
Or you can import everything except some symbols:
; everything except circle and ellipse
(require (except-in 2htdp/image circle))
And there is no reason not using racket or racket/base as language when you know this.

Little Schemer and Racket

I'm starting to read the Little Schemer and now instead of PLT Scheme we have Racket. I would like to know if Racket is suitable for doing the exercises in the book or do I need to get another true Scheme compiler. Before I forgot to tell you, my OS is Windows x64.
The book, language and paradigm is complex enough, I would love to avoid struggling with a compiler.
DrRacket is the (r)evolution of DrScheme; DrRacket will work perfectly for the exercises in "The Little Schemer". Just don't forget to:
In the Language dialog, choose "Use the language declared in the source"
Write #lang racket at the top of each file you create
Implement the atom? predicate in each file as explained at the very beginning of the book
If you're going to re-implement an existing procedure, do so in a separate tab or window, because trying to rewrite a procedure in the edit window will result in a duplicate definition for identifier error. If necessary, use several files for saving the procedure definitions
You really just need the atom? function. What’s described in the book's preface is essentially:
(define (atom? x)
(and (not (pair? x)) (not (null? x))))
As mentioned, it should satisfy this test:
(atom? '()) ;=> #f
Note that there is also a definition in Racklog that will not satisfy that test.
A more detailed discussion on atom? is here.
Despite the book's suggestion to implement add1 and sub1, Racket does already provide them.
BTW, I use Vim for editing Racket, but a few other editors are capable.
I have had the author of the book as a professor. He now uses Racket himself, but he uses Emacs as a text editor.
Racket/Scheme are interchangeable. You should be able to answer any exercise with it. Good luck.
Also, I recommend downloading Dr. Racket as your interpreter.

Differences between Guile Scheme and Standard Scheme (in Racket IDE)?

I've got a bunch of "legacy" Guile Scheme code that I want to get running in the Racket Scheme IDE. There appear to be enough differences to make this a non-trivial exercise. (My level of Scheme knowledge is the level to complete the The Little Schemer).
My question is:
What are the differences between Guile Scheme and Standard Scheme (in the Racket IDE)?
In light of these differences, in general, what are the steps I'll need to take to convert some Guile Scheme Code to standard Scheme?
Additional: (happy with divergence between Racket Scheme and R5RS/R6RS) - what I want is to get 'something' to run in the Racket IDE - rather than the Racket language.
If by "Standard Scheme (in the Racket IDE)," you mean the Racket language, i.e., what you get when you prefix your code with #lang racket, then the top four differences to look out for are:
a different module system
a different macro system (depending on how old your code is)
immutable cons-cells (unless you import mutable ones)
no one-armed ifs in Racket (use when)
To port code from Guile to Racket, find out which files are "at the bottom" of your dependencies, i.e., find the files that do not depend on other files.
Open such a file in Racket, add the line #lang racket at the top, and try to run it.
You will most likely encounter some "unbound identifier" errors.
If you are lucky, the function is present in Racket, but not included in the "racket" language. Search for the name in the Racket documentation, and if you find it, then use (require ...) to import the name into your program.
Then run the program again to find the next error.
Some function are named differently in Guile and Racket, so look up the name in the Guile documentation and see what it does. Then open the Racket documentation on the same subject, and see what it is called in Racket.
In some cases you may have to make bigger changes. If you can't find some piece of functionality in the Racket documentation, then try asking the mailing list. It could be that it simply has a different name, or that somebody implemented it and put it on PLaneT (thus it will no appear in the documentation until you have installed the package).
Example of importing srfi/1 into the R5RS language.
#lang r5rs
(#%require srfi/1)
(xcons 1 2)
Differences from R4RS code to modern Scheme?
One thing to look out for is that in R4RS the empty list '() counted as false, not it is interpreted as true.
See this question for more things to look out for:
Running SICP Pattern Matching Rule Based Substitution Code
See also this list of changes from the R5RS standard:
List of changes from R4RS to R5RS

What Scheme Does Ghuloum Use?

I'm trying to work my way through Compilers: Backend to Frontend (and Back to Front Again) by Abdulaziz Ghuloum. It seems abbreviated from what one would expect in a full course/seminar, so I'm trying to fill in the pieces myself.
For instance, I have tried to use his testing framework in the R5RS flavor of DrScheme, but it doesn't seem to like the macro stuff:
src/ghuloum/tests/tests-driver.scm:6:4: read: illegal use of open square bracket
I've read his intro paper on the course, An Incremental Approach to Compiler Construction, which gives a great overview of the techniques used, and mentions a couple of Schemes with features one might want to implement for 'extra credit', but he doesn't mention the Scheme he uses in the course.
Update
I'm still digging into the original question (investigating options such as Petit Scheme suggested by Eli below), but found an interesting link relating to Gholoum's work, so I am including it here.
[Ikarus Scheme](http://en.wikipedia.org/wiki/Ikarus_(Scheme_implementation)) is the actual implementation of Ghuloum's ideas, and appears to have been part of his Ph.D. work. It's supposed to be one of the first implementations of R6RS. I'm trying to install Ikarus now, but the configure script doesn't want to recognize my system's install of libgmp.so, so my problems are still unresolved.
Example
The following example seems to work in PLT 2.4.2 running in DrEd using the Pretty Big
(require lang/plt-pretty-big)
(load "/Users/donaldwakefield/ghuloum/tests/tests-driver.scm")
(load "/Users/donaldwakefield/ghuloum/tests/tests-1.1-req.scm")
(define (emit-program x)
(unless (integer? x) (error "---"))
(emit " .text")
(emit " .globl scheme_entry")
(emit " .type scheme_entry, #function")
(emit "scheme_entry:")
(emit " movl $~s, %eax" x)
(emit " ret")
)
Attempting to replace the require directive with #lang scheme results in the error message
foo.scm:7:3: expand: unbound identifier in module in: emit
which appears to be due to a failure to load tests-driver.scm. Attempting to use #lang r6rs disables the REPL, which I'd really like to use, so I'm going to try to continue with Pretty Big.
My thanks to Eli Barzilay for his patient help.
The language he uses is most likely Chez Scheme. Regardless, the R5RS language in PLT is a pretty strict version of R5RS, with extensions like square brackets throwing errors -- and you may get more mileage using the default #lang scheme language. (Or, if that fails, try and see if you can work with Petit -- the free version of Chez.)
You can see setup instructions for running it here on Ubuntu x86.
The installation download for Petite Scheme are here.

Resources