Newsgroups: comp.lang.scheme
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!oitnews.harvard.edu!news.sesqui.net!news-out.internetmci.com!newsfeed.internetmci.com!chi-news.cic.net!uwm.edu!spool.mu.edu!torn!watserv3.uwaterloo.ca!marshlice
From: MACHAPUT@ARTSU1.uwaterloo.ca (Matthew Allan Chaput)
Subject: Binding 'Self'
Message-ID: <4733oo$9gg_001@watstar.uwaterloo.ca>
Summary: How do I bind the variable 'self' in my object system?
Keywords: object oriented self reference
Sender: news@watserv3.uwaterloo.ca
Nntp-Posting-Host: marshlice.watstar.uwaterloo.ca
Organization: University of Waterloo
X-Newsreader: News Xpress Version 1.0 Beta #3
Date: Mon, 30 Oct 1995 17:58:48 GMT
Lines: 43

Hi! I'm a novice, self-taught-by-osmosis, and I'm trying to do an 
object system in scheme (ya, I know, yet another) as an exercise to see 
how much I know. I'm trying to do something like the Self language, a 
classless, prototype-based system with "slots" that can be data or 
functions. I'm also trying to do it with a message-passing model rather 
than a generic function model, because I love Smalltalk so much.

The main thing is I'd like statements using my object system to be 
valid Scheme expressions; that is, I *DON'T* want to write my own 
interpreter, though I know I might have to do some interpreter-like 
things. (The message passing model sort of breaks down in real Scheme, 
because, ferinstance "(5 'factorial)" obviously won't work)

Anyway, right now I'm using an object-maker something like this:

(define (object-maker proto slots)
  (lambda (msg . args)
    (cond ((eq? msg 'proto) proto)
          ((eq? msg 'self)  self)   ; <--- there's the rub
          (else (meaning msg)))))
[where "meaning" determines (somehow!) if "msg" is a slot in the 
current object; if it isn't, the message is sent to the prototype (up 
the chain); if it IS a slot, it determines if it is self-evaluating 
(and returns it), or if it is a function (and applies it to "args")]

*THE PROBLEM IS* (aside from some others): How on earth do I bind self? 
How can a function (the inner lambda) call itself when it doesn't know 
its own name???? This really has me stumped, but everybody else who 
writes a Scheme object system must have solved it, so maybe it's 
straightforward. (I really need to audit a class in Scheme before I 
graduate!!!)

Any help or pointers would be greatly appreciated!

Thanks,

Matthew Allan "Eeyore" Chaput
(if there's a double .sig, it's not my fault, my newsreader is screwy)



------------------------------------------------------------------------------
Matthew Allan Chaput
