使用图形绘制线定义过程

ctr*_*lor 2 lisp graphics scheme

你能看出这个有什么问题:

(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) ))
Run Code Online (Sandbox Code Playgroud)

当我这样称呼时:

( begin 
     (define w (make-graphics-device 'x))
     (box  w .10 .10 .20 .20) )
Run Code Online (Sandbox Code Playgroud)

我得到一个错误:

;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>
Run Code Online (Sandbox Code Playgroud)

这有效:

(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) )
Run Code Online (Sandbox Code Playgroud)

我看不出差异!

Eli*_*lay 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))
Run Code Online (Sandbox Code Playgroud)