paint-hires: unbound identifier in: paint-hires - scheme

I was trying to follow how to do scheme and sicp from Which lang packet is proper for SICP in Dr.Racket?
but when I run code in the accepted answer
#lang sicp
(paint-highres (below (beside diagonal-shading
(rotate90 diagonal-shading))
(beside (rotate270 diagonal-shading)
(rotate180 diagonal-shading))))
I get error
paint-hires: unbound identifier in: paint-hires
I have installed the sicp package.
Anyone know what the problem is?

The paint-hires function is a left-over form the original MIT Scheme implementation. Back then it the "high resolution" was too slow to use, while experimenting - so paint-hires was used to get a "final" image.
When the original MIT Scheme implementation of the SICP Picture Language was ported to PLT Scheme paint-hires was kept.
Recently (within a year or two) the SICP Picture Language was reimplemented on modern Racket. This gives you the ability to use the Picture language with a resolution of your choice, colors! (the original MIT Scheme was used on monochrome displays) and more.
Make a copy of: "main.rkt" and einstein2.jpg" and save them in the same folder.
Open "main.rkt" in DrRacket and run it.
Look at the bottom for examples.
Add your own program at the bottom of "main.rkt".
Look through the files for how to use colors etc.
Both files are here:
https://github.com/sicp-lang/sicp/tree/master/sicp-pict

#sorawee-porncharoenwase thank you for the docs link. #soegaard thanks for the context for the recent changes to DrRacket.
What finally worked for me was this
#lang sicp
(#%require sicp-pict)
(paint (below (beside diagonal-shading
(rotate90 diagonal-shading))
(beside (rotate270 diagonal-shading)
(rotate180 diagonal-shading))))
I think the docs incorrectly say to use paint-hires.

Related

DrRacket/Scheme circle undefined

I'm a beginner learning Scheme. I tried to follow the quick introduction to get familiar with the syntax, but stuck in step 3. When I type (circle 10), it gives me "circle: undefined;
cannot reference an identifier before its definition" Do I miss some library or I have to define circle first?
output error
You are using the racket language, but Racket is actually an ecosystem of many programming languages. The Quick tutorial uses the slideshow language, a variant of Racket designed for creating pictorial programs and slideshows. As mentioned in section 2 of the tutorial, change the first line of your program to this:
#lang slideshow
…click Run, and circle should now be defined.

How to run Picture language examples of SICP /scheme in repl?

I'm beginner in SICP. I'm reading section 2.2.4, A Picture Language. I'm stuck with it's example. I didn't understand, How to run these examples?
As given in book, wave is supposed to be a primitive procedure. But When I tried to execute it, REPL throw an error as given below
1 ]=> wave
;Unbound variable: wave
Similarly when I tried to execute first example of this section, REPL throw an error
1 ]=> (define wave2 (beside wave (flip-vert wave)))
;Unbound variable: wave
I didn't understand, what's going wrong? Any help would be appreciated. Thanks.
In DrRacket IDE there is a SICP compatibility language. Using DrRacket helps format code, identify errors and it has a debugger. It also supports standard Scheme as well as it's own dialect, racket, which is very similar but has lots of libraries like most modern languages.
To install (after you have installed DrRacket)
From terminal run:
raco pkg install sicp
You get lots of output and perhaps some WARNINGS. Restart DrRacket and replace #lang racket with #lang sicp. To get the picture language add (#%require sicp-pict), thus this example should work nicely:
#lang sicp
(#%require sicp-pict)
(paint-hires (below (beside diagonal-shading
(rotate90 diagonal-shading))
(beside (rotate270 diagonal-shading)
(rotate180 diagonal-shading))))
This is a short version of an answer to Which lang packet is proper for SICP in Dr.Racket?

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.

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

Cannot load File in Scheme, (using Simply Scheme Book and PLT 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.)

Resources