Extracting the number of members inside a structure

51 views Asked by At

How would I go about extracting the number of members inside a structure for a cond.

For example. I have two different structures, one with two members and another with three. How would I extract the number of members in my structures in this case?

(define-struct triangle (vertex1 vertex2 vertex3)) (define-struct rectangle (vertex1 vertex2))

(define (shape=? shape1 shape2) ...)

Where shape1 can be a triangle or rectangle.

I may be approaching the question wrong, but I need shape=? to produce true if shape1 and shape2 are both triangles or both rectangles, and false otherwise.

Thank you.

1

There are 1 answers

1
C. K. Young On

Your problem description pretty much describes what's required:

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