Min Max Scheme coord.x0 y0 x1 y1

时间:2013-10-07 11:06:19

标签: functional-programming scheme max min

;; makeRectangle -- constructor for 'rectangle

(define makeRectangle
  (lambda (x0 y0 x1 y1)
       (makeGraph 'rectangle
               (list (makePoint x0 y0)
                     (makePoint x1 y1)))))

(makeRectangle 3 2 1 7)必须返回(rectangle (point 1 7) (point 3 2)) 我将获得(makeRectangle 1 2 3 7)(makeRectangle 1 7 3 2)的相同回报,我必须使用:

min x0 x1 min y0 y1 
max x0 x1 max y0 y1

但我不知道该怎么做。你能帮我解决这个问题吗?提前谢谢。

1 个答案:

答案 0 :(得分:1)

你的意思是:

(define makeRectangle
  (lambda (x0 y0 x1 y1)
    (makeGraph 'rectangle
               (makePoint (min x0 x1) (max y0 y1))
               (makePoint (max x0 x1) (min y0 y1)))))

,例如

-> (makeRectangle 3 2 1 7)
'(rectangle (point 1 7) (point 3 2))

-> (makeRectangle 1 2 3 7) 
'(rectangle (point 1 7) (point 3 2))

-> (makeRectangle 1 7 3 2) 
'(rectangle (point 1 7) (point 3 2))

-> (makeRectangle 3 7 1 2)
'(rectangle (point 1 7) (point 3 2))