I am going through SICP as a self-study and am on the picture language section in Chapter 2. I have been using DrRacket for the earlier exercises, but I get compilation errors when trying to do an exercise based on the 'draw-line' picture function in this section of the book.
Specifically, this code ...
(define (segments->painter segment-list)
(lambda (frame)
(for-each
(lambda (segment)
(draw-line
((frame-coord-map frame) (start-segment segment))
((frame-coord-map frame) (end-segment segment))))
segment-list)))
...produces this error ...
draw-line: unbound identifier in module in: draw-line
So I did a bit of research on this forum and installed the SICP package that Neil Van Dyke offers (http://www.neilvandyke.org/racket-sicp/#(part._usage)). I followed all of the steps, changed the language to SICP as directed, but still get the same error.
I assumed that the purpose of this package was to have defined this 'built-in' function (as well as others in the book). Just to anticipate some questions, I do not have 'require' statements in the file and used '#lang planet neil/sicp' to specify the language instead of using the menu (I also tried changing the language to SICP using the menu and get an even stranger error; see the postscript below). My environment is Windows 7 and the version of DrRacket is 5.3.1.
Perhaps I am just making a rookie mistake; any insight would be appreciated.
Thanks.
PS: For those interested, when I set the language to 'SICP (PLaneT 1.17)' using the menu, I get the following error for any definition that I try to compile (even the most trivial)...
<unsaved editor>:1:0: #%top-interaction: unbound identifier;
also, no #%app syntax transformer is bound in: #%top-interaction
In Racket, these definitions solved my problems with the drawings in chapter 2 of SICP, I solved successfully the exercises after that:
(require graphics/graphics)
(open-graphics)
(define vp (open-viewport "A Picture Language" 500 500))
(define draw (draw-viewport vp))
(define (clear) ((clear-viewport vp)))
(define line (draw-line vp))
(define (make-vect x y)
(cons x y))
(define (xcor-vect v)
(car v))
(define (ycor-vect v)
(cdr v))
(define (add-vect v1 v2)
(make-vect (+ (xcor-vect v1)
(xcor-vect v2))
(+ (ycor-vect v1)
(ycor-vect v2))))
(define (sub-vect v1 v2)
(make-vect (- (xcor-vect v1)
(xcor-vect v2))
(- (ycor-vect v1)
(ycor-vect v2))))
(define (scale-vect s v)
(make-vect (* s (xcor-vect v))
(* s (ycor-vect v))))
(define (make-frame origin edge1 edge2)
(list origin edge1 edge2))
(define (origin-frame f)
(car f))
(define (edge1-frame f)
(cadr f))
(define (edge2-frame f)
(caddr f))
(define (frame-coord-map frame)
(lambda (v)
(add-vect
(origin-frame frame)
(add-vect (scale-vect (xcor-vect v)
(edge1-frame frame))
(scale-vect (ycor-vect v)
(edge2-frame frame))))))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With