2015-06-11 48 views
1

我會如何去提取結構中cond的成員數量。提取結構內成員的數量

例如。我有兩個不同的結構,一個有兩個,另一個有三個。在這種情況下,我將如何提取我的結構中的成員數量?

(定義-結構三角形(vertex1 vertex2 vertex3)) (限定-結構矩形(vertex1 vertex2))

(定義(形狀=?shape1 shape2) ...)

凡shape1可以是三角形或矩形。

我可能會接近錯誤的問題,但我需要shape =?如果shape1和shape2都是三角形或兩個矩形,則生成true,否則爲false。

謝謝。

回答

1

您的問題說明相當多描述真實需要什麼:

(define (shape=? shape1 shape2) 
    (or (and (triangle? shape1) (triangle? shape2)) 
     (and (rectangle? shape1) (rectangle? shape2)))) 
+0

謝謝!我絕對是在想這件事。 – prot