DrRacket/Scheme circle undefined - scheme

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.

Related

paint-hires: unbound identifier in: paint-hires

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.

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.

Different kinds of continuations in Racket

Can someone give a relatively simple example of the differences in Racket between call-with-composable-continuation and call-with-current-continuation.
I've worked through the examples in the Racket Guide 10.3 of call-with-composable-continuation, and the examples of call-with-current-continuation in The Scheme Programming language section 3.3 but I'm not clear on the difference.
Could someone give an example where they would give different results in the same context.
A very thorough explanation is found in the paper "Adding Delimited and Composable Control to a Production Programming Environment" by Flatt, Yu, Findler and Felleisen.
http://www.cs.utah.edu/plt/publications/icfp07-fyff.pdf

Where to find Scheme library functions?

Is there a reference website to look up syntax for Scheme library function like http://www.cplusplus.com/reference/?
I'm looking for syntax of fold, but google gave me nothing :(
Thanks,
fold is from SRFI 1. Many functions have good documentation if you know where it "comes from".
Also, since you're using Racket (as mentioned in your previous questions), you should check out the Racket documentation. It has a very nice search facility. (Also, you might like to know about Racket's foldl, which is identical to SRFI 1's fold.)

Examples to show how to use Racket lexer generator?

I am playing with the Racket recently, currently implementing a lexer for a subset of scripting language...and wondering whether there are more examples to show how to use the lexer generator in Racket?
I understand the calculator example in the doc, but it is too simple to show the full features...
I am especially curious how to reference position of each character....
The libraries at PLaneT are a great resource for more elaborate examples.
Try for example the Infix Parser .

Resources