你能看出这有什么问题:
(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) ))
当我这样称呼时:
( begin
(define w (make-graphics-device 'x))
(box w .10 .10 .20 .20) )
我得到一个错误:
;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>
这有效:
(begin
(define w (make-graphics-device 'x))
(graphics-draw-line w .1 .1 .1 .2)
(graphics-draw-line w .1 .2 .2 .2)
(graphics-draw-line w .2 .2 .2 .1)
(graphics-draw-line w .2 .1 .1 .1) )
我看不出差异!
答案 0 :(得分:6)
不要只用()
s对表达式进行分组 - 它会尝试将第一个结果用作函数,但值为#!unspecific
- 绝对不是函数。
使用此:
(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))