Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!howland.reston.ans.net!ix.netcom.com!netcom.com!kcooper
From: kcooper@netcom.com (Ken Cooper)
Subject: Re: Adding methods with method code in Smalltalk/V for Win32?
Message-ID: <kcooperD7J06K.IzM@netcom.com>
Organization: NETCOM On-line Communication Services (408 261-4700 guest)
References: <m-rd0107.798661334@elliemae>
Date: Mon, 24 Apr 1995 06:18:20 GMT
Lines: 35
Sender: kcooper@netcom8.netcom.com

If I read you correctly, you're actually working on the classic
'add accessors' problem.  Here's some code you might
find useful.  It's part of an extension to our edIt product
(a programmer's editor component that plugs into Visual Smalltalk). 
If I guessed wrong, you still have an example of how you can 
generate code on the fly.

If I guessed right, if/when you upgrade to VST, you might find 
edIt interesting.  Just in case, there's a fully functional demo 
available in the st.cs.uiuc.edu archive, in the file 
pub/cooper/edIt/editdemo.exe.

Ken Cooper
Cooper & Peters, Inc.

!Behavior methods!
  
addAccessorsFor: aVariableName

    "Private - Adds get and set methods for aVariableName.
    Copyright 1995, Cooper & Peters, Inc."
    | s |

    #addedByCnP.
    s := ReadWriteStream on: String new.
    s nextPutAll: '!!', self name, ' methods!!'; cr.
    s nextPutAll: aVariableName; cr; cr.
    s nextPutAll: '    ^', aVariableName, '!! !!'.
    s fileIn.

    s := ReadWriteStream on: String new.
    s nextPutAll: '!!', self name, ' methods!!'; cr.
    s nextPutAll: aVariableName, ': anObject'; cr; cr.
    s nextPutAll: '    ', aVariableName, ' := anObject.!! !!'.
    s fileIn.! !
