sicp-lang/sicp

segments->painter :: target is not an object

jrgtt opened this issue · 6 comments

jrgtt commented

Hello, thanks for keeping up such project. It's been really helpful for my SICP studies. However I can't make it work for the exercise 2.49, I hope this doesn't come as do my homework type of issue, but debugging the code seems a bit cryptic for me.

#lang sicp
(#%require sicp-pict)

(define tl (make-vect 0 10))
(define tr (make-vect 10 10))
(define bl (make-vect 0 0))
(define br (make-vect 10 0))

(define segments
  (vects->segments
   (list bl tl tr br bl)))

(define origin (make-vect 0 0))
(define frame (make-frame origin tl br))

(paint ((segments->painter segments) frame)) ;; fails with "target is not an object. target: #f"

When I check the code here, there's a call to send which in turn use dc from (current-dc) whereas it seems to be #f at the start. I don't know anything of racket but I suspect that the current-dc call should take another value at this point. But how do I arrive to that?

The procedure paint calls the painter with its own frame (unit vectors along the first and second axis), so when using paint you don't need to supply a frame.

However the error message you see is misleading, so we need to fix the error message.

#lang sicp
(#%require sicp-pict)

(define tl (make-vect  0 1))
(define tr (make-vect  1 1))
(define bl (make-vect  0 0))
(define br (make-vect  1 0))

(define segments
  (vects->segments
   (list bl tl tr br bl)))

(define origin (make-vect 0 0))
(define frame (make-frame origin tl br))

(paint (segments->painter segments))

Btw - sicp-pict is meant to be used like this:

#lang racket
(require sicp-pict)

jrgtt commented

@soegaard thanks a lot for the clarification.

About using #lang sicp, it was taken from the Examples section in Racket docs.

Hmm. Maybe it works fine in #lang sicp too?

I reopened the issue - we still need to improve the error message.

jrgtt commented

They seem to work fine with sicp as language, I've did the previous exercises like implementations of square-limit and corner-split without any problems.

Thanks for fixing this.