你能看出这有什么问题吗:
(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) )
我看不出有什么区别!
最佳答案
不要仅使用 ()
对表达式进行分组 - 这将尝试将第一个结果用作函数,但其值为 #!unspecior
-- 绝对不是一个函数。
使用这个:
(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))
关于graphics - 使用graphics-draw-line定义过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6272179/