每次运行此代码时,都会收到错误消息:“define:只需要一个函数体表达式,但找到1个额外部分。”我一次又一次地尝试解决这个问题,但我还没有找到解决方案。有谁知道如何解决它?很抱歉长码,我想我应该把它包括在内,否则就没有意义了。谢谢!
(define MT (empty-scene 50 50))
; A Polygon is one of:
; – (list Posn Posn Posn)
; – (cons Posn Polygon)
; A NELoP is one of:
; – (cons Posn empty)
; – (cons Posn NELoP)
; Polygon -> Image
; adds an image of p to MT
(define (render-polygon p)
(local
[;Polygon -> Posn
; extracts the last item from p
(define (last p)
(cond
[(empty? (rest (rest (rest p)))) (third p)]
[else (last (rest p))]))]
[;Image Posn Posn -> Image
(define (render-line im p q)
(add-line
im (posn-x p) (posn-y p) (posn-x q) (posn-y q) "red"))]
[;NELop -> Image
;connects the posns in p in an image
(define (connect-dots p)
(cond
[(empty? (rest p)) MT]
[else
(render-line
(connect-dots (rest p)) (first p) (second p))]))])
(render-line (connect-dots p) (first p) (last p)))
新代码(仍无效):
; Polygon -> Image
; adds an image of p to MT
(define (render-polygon p)
(local
[;Polygon -> Posn
; extracts the last item from p
(define (last p)
(cond
[(empty? (rest (rest (rest p)))) (third p)]
[else (last (rest p))]))
;Image Posn Posn -> Image
(define (render-line im p q)
(add-line
im (posn-x p) (posn-y p) (posn-x q) (posn-y q) "red"))
;NELop -> Image
;connects the posns in p in an image
(define (connect-dots p)
(cond
[(empty? (rest p)) MT]
[else
(render-line
(connect-dots (rest p)) (first p) (second p))]))
(render-line (connect-dots p) (first p) (last p))]))
答案 0 :(得分:2)
您的render-line
表达式必须 local
表单,而不是之后。此外,您define
的所有local
应位于(local [(define (last p)
...)
(define (render-line im p q)
...)
(define (connect-dots p)
...)]
(render-line ...))
中的一个子表单中,而不是每个子表单中的每个子表单。所以,它应该看起来像:
{{1}}