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)
  (cond
    ((and (atom? obj1) (atom? obj2))
      #t )
    ((atom? obj1)
      #f )
    ((atom? obj2)
      #f)
    (else
      (and (similar-struct? (car obj1) (car obj2))
           (similar-struct? (cdr obj1) (cdr obj2)) ))))
saulgoode
 
Posts: 45
Joined: Tue Dec 14, 2010 1:39 am

Previous

Return to Scheme

Who is online

Users browsing this forum: No registered users and 0 guests