15
votes

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:

  1. What are the differences between Guile Scheme and Standard Scheme (in the Racket IDE)?
  2. 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.

1
If you've stuck closely with the R5RS and R6RS standards, then the compatibility languages that are built-in to Racket may help. See: docs.racket-lang.org/guide/standards.htmldyoo
Could you specify which language you are declaring in DrRacket (R5RS/racket/etc)? Could you give examples for where the code is breaking?robbyphillips
@oobivat I've deliberately swept the net wide - the question behind my question is "what is the non-standard stuff in guile scheme". If it makes the question easier to answer - then I'd phrase it as "What is likely to break with my 1994 guile scheme code when running in Racket set to R5RS - and how do I fix it?"hawkeye
Well, I haven't done much with racket's R5RS implementation, but from playing around with it a little bit, it seems to lack most things implemented in the SRFI's. For instance there is no random procedure. According to this page it seems like you would be able to load whatever functionality you want. Unfortunately I was unable to find anything like a diff between the to languages.robbyphillips
@oobivat If you need srfi-1 functions you can use #%require to import it. See example in the answer below (line breaks are deleted in comments).soegaard

1 Answers

6
votes

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