is-a? implemented, possible bug.

From: Clifford Beshers <>
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?


(define (is-a? class obj)

  (define (do-is-a? obj-class)
     ((eq? class obj-class) #t)
      (let loop ((supers (class-direct-supers obj-class)))
           (if (null? supers)
             (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)
   (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
STk> (load "isa.scm")
STk> a
#[<a> #p8056c60]
STk> x
#[<x> #p8057254]
STk> (is-a? <a> x)
STk> (is-a? <a> x)
STk> (is-a? <a> x)
STk> (load "isa.scm")
STk> (is-a? <a> x)
STk> Bye.



Clifford Beshers                Office:  (212) 939-7087   Lab: (212) 939-7101
Columbia University             Fax:     (212) 666-0140   
500 West 12Oth St., Room 450    WWW:
New York, NY 10027              Email:
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