is-a? implemented, possible bug.

From: Clifford Beshers <beshers_at_cs.columbia.edu>
Date: Sat, 6 Jan 1996 01:32:00 -0500

Well, I was wrong, class-direct-supers takes a class, not an instance,
so the function I wanted is possible.

In include it here, along with a mysterious transcript, which I think
might reveal a bug in the STk interpreter.

When I (load "isa.scm") the first time, is-a? gives the wrong answer,
but if I load it again, it give the correct answer. Can anyone
explain this as an error in my code?



****************************************************************
isa.scm
****************************************************************


(define (is-a? class obj)

  (define (do-is-a? obj-class)
    (cond
     ((eq? class obj-class) #t)
     (else
      (let loop ((supers (class-direct-supers obj-class)))
           (if (null? supers)
               #f
             (or (do-is-a? (car supers))
                 (loop (cdr supers))))))))

  (do-is-a? (class-of obj)))



(define-class <a> ()
  ())

(define-class <b> ()
  ())

(define-class <x> (<a> <b>)
  ())

(define a (make <a>))
(define b (make <b>))
(define x (make <x>))


(define (test-is-a)
  (and
   (eq? (is-a? <x> x) #t)
   (eq? (is-a? <a> x) #t)
   (eq? (is-a? <b> x) #t)

   (eq? (is-a? <x> a) #f)
   (eq? (is-a? <a> a) #t)
   (eq? (is-a? <b> a) #f)

   (eq? (is-a? <x> b) #f)
   (eq? (is-a? <a> b) #f)
   (eq? (is-a? <b> b) #t)

   (eq? (is-a? (class-of 4.5) 4) #t)
   (eq? (is-a? (class-of 4) 4.5) #f)

   ))


****************************************************************
Snow transcript
****************************************************************
bash$ snow
Welcome to the STk interpreter version 3.0b1 [Linux-1.X-ix86]
Copyright (C) 1993,1994,1995 Erick Gallesio - I3S - CNRS / ESSI
<eg_at_unice.fr>
STk> (load "isa.scm")
#[undefined]
STk> a
#[<a> #p8056c60]
STk> x
#[<x> #p8057254]
STk> (is-a? <a> x)
#f
STk> (is-a? <a> x)
#f
STk> (is-a? <a> x)
#f
STk> (load "isa.scm")
#[undefined]
STk> (is-a? <a> x)
#t
STk> Bye.
bash$


Thanks,

Cliff

-- 
Clifford Beshers                Office:  (212) 939-7087   Lab: (212) 939-7101
Columbia University             Fax:     (212) 666-0140   
500 West 12Oth St., Room 450    WWW:     http://www.cs.columbia.edu/~beshers
New York, NY 10027              Email:   beshers_at_cs.columbia.edu
Received on Sat Jan 06 1996 - 15:46:20 CET

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST