List Struture Equality

Discussion of Scheme and Racket

Re: List Struture Equality

Postby saulgoode » Thu Mar 22, 2012 5:17 pm

The following assumes that for (sub)lists to be considered similar to each other, they must have the same number of elements.

Code: Select all
(define (similar-struct? obj1 obj2)
    ((and (atom? obj1) (atom? obj2))
      #t )
    ((atom? obj1)
      #f )
    ((atom? obj2)
      (and (similar-struct? (car obj1) (car obj2))
           (similar-struct? (cdr obj1) (cdr obj2)) ))))
Posts: 45
Joined: Tue Dec 14, 2010 1:39 am


Return to Scheme

Who is online

Users browsing this forum: Majestic-12 [Bot] and 2 guests