[plt-scheme] Organizing Code, Pt.2

From: Eli Barzilay (eli at barzilay.org)
Date: Tue Mar 14 10:18:44 EST 2006

On Mar 14, Kevin A. Smith wrote:
> Danny Yoo wrote:
> 
> >>(module module-a
> >>   (lib "swindle.ss" "swindle")
> >>
> >>   (defclass test-parent()
> >>      (name :accessor name :initarg :name))
> >>
> >>   (provide test-parent))
> >>
> >>Requiring this module allows me to create instances of the class but
> >>inspecting these instances fail:
> >>
> >>=> (require (lib "swindle.ss" "swindle"))
> >>=> (require "module-a.scm")
> >>=> (define tp (make test-parent :name "Parent"))
> >>=> (display-object tp)
> >>#<test-parent:Parent>=> (name tp)
> >>reference to undefined identifier: name

[...]

> Yep. slot-ref seems to work, so that's a possibility. I'm still curious 
> as to why (name tp) fails. I think I'm missing something about how 
> Swindle generates accessors because mzscheme complains about duplicate 
> identifier definitions when I add:
> 
> (define (name tp)
>    (slot-ref tp 'name))

Swindle defines a `name' accessor, but you don't provide it.  Defining
your own collides with the one that is already there.  If you just add
a `(provide name)' it should work.

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


Posted on the users mailing list.