Can you see what is wrong with this:
(define (box d x1 y1 x2 y2) (
(graphics-draw-line d x1 y1 x1 y2)
(graphics-draw-line d x1 y2 x2 y2)
(graphics-draw-line d x2 y2 x2 y1)
(graphics-draw-line d x2 y1 x1 y1) ))
When I call it like this:
( begin
(define w (make-graphics-device 'x))
(box w .10 .10 .20 .20) )
I get an errer:
;The object #!unspecific is not applicable.
;To continue, call RESTART with an option number:
; (RESTART 2) => Specify a procedure to use in its place.
; (RESTART 1) => Return to read-eval-print level 1.
2 error>
This works:
(begin
(define w (make-graphics-device 'x))
(graphics-draw-line w .1 .1 .1 .2)
(graphics-draw-line w .1 .2 .2 .2)
(graphics-dra开发者_JS百科w-line w .2 .2 .2 .1)
(graphics-draw-line w .2 .1 .1 .1) )
I can't see the difference!
Don't just group expressions with ()
s -- that will try to use the result of the first as a function, but the value is #!unspecific
-- definitely not a function.
Use this:
(define (box d x1 y1 x2 y2)
(graphics-draw-line d x1 y1 x1 y2)
(graphics-draw-line d x1 y2 x2 y2)
(graphics-draw-line d x2 y2 x2 y1)
(graphics-draw-line d x2 y1 x1 y1))
精彩评论