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

1

15

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.

Jackelinejackelyn answered 17/5, 2012 at 13:7 Comment(8)
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.htmlGros
Could you specify which language you are declaring in DrRacket (R5RS/racket/etc)? Could you give examples for where the code is breaking?Sense
@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?"Jackelinejackelyn
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.Sense
@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).Loudmouthed
@Loudmouthed Yes, I am aware. The page I link to in my comment has that information. My thinking is that one of the difficulties in migrating OP's code will be the SRFI's that guile has natively implemented, but that will need to be #%require'd in racket.Sense
@oobivat Hi. I thought by "... it seems to lack most things implemented in the SRFI's" you meant srfi's weren't present in Racket at all. They are not present in the Racket implementation of R5RS, since that goes by the letter of the standard, and has no extras. If I recall correctly, not even square brackets are allowed. However (as you know) one can import common extensions with #%require. What wasn't clear from the beginning was whether hawkeye is porting R5RS code (which happen to run in Guile) or is porting Guile code (which uses Guile extensions). I see now that it is code from 1994Loudmouthed
I see now that the code is from 1994, which means that the code is not R5RS, but rather R4RS code (since R5RS came out in 1998). So the question is what to look out for in R4RS code! See the updated answer below.Loudmouthed
L
7

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

Loudmouthed answered 17/5, 2012 at 13:8 Comment(2)
I suspect the poster might have been asking about the R5RS or R6RS languages in DrRacket.Connell
Thanks Sam - I was sweeping the net wide to get all possible information. I think you're saying that the comment above is Racket specific - and doesn't apply to R5RS.Jackelinejackelyn

© 2022 - 2024 — McMap. All rights reserved.