[Cuis-dev] Gatekeeper example from "Discovering Smalltalk"

Boris Shingarov shingarov at labware.com
Mon Jan 27 03:15:56 PST 2025


"Unsafe hackery" it may be, but this has been my favorite kind of thing
and I find it essential to the spirit of Smalltalk.  Have you seen
LaLonde and Van Gulik's https://dl.acm.org/doi/10.1145/62084.62094 ?
I have even been thinking (sor some while now, but never find the time
to actually play with it) about how to get rid of ^ as a language
construct and replace it with just another message send (#^ would have
"prefix precedence" but there is nothing difficult about those, Leandro
has been doing them for a long time).  Getting the VM to drop the
current frame would be the tricky part.  Something along the lines of
thisContext become: ...?

On Sun, Jan 26, 2025 at 01:56:13PM -0600, Mark Volkmann via Cuis-dev wrote:
> I recently read the book "Discovering Smalltalk". I know it's quite dated
> and it's based on Smalltalk/V instead of Smalltalk-80, but I still learned
> a lot from it.
> 
> I implement the Gatekeeper example described on pages 428-430 in Cuis. It
> demonstrates using the becomes: method to track all messages sent to a
> given object. I got it working, but I had to make a small modification to
> the ProtoObject instance method becomes:. I'm wondering if my change would
> break other uses of this method.
> 
> I replaced the line
> 
> selfMethod = otherObjectMethod ifFalse: [
> 
> with
> 
> selfMethod ~= nil and:
> [otherObjectMethod ~= nil] and:
> [selfMethod ~= otherObjectMethod] :: ifTrue: [
> 
> Here's my working Gatekeeper code where I renamed that class to
> HistoryProxy.
> 
> Object subclass: #HistoryProxy
>     instanceVariableNames: 'history object'
>     classVariableNames: ''
>     poolDictionaries: ''
>     category: 'Demo'
> 
> "class method"
> on: anObject
>     ^ self new on: anObject
> 
> "instance method"
> on: anObject
>     history := OrderedCollection new.
>     object := anObject shallowCopy.
>     anObject become: self
> 
> "instance method"
> doesNotUnderstand: aMessage
>     "Record the message and reroute it to the object."
>     history add: aMessage.
>     ^ aMessage sendTo: object.
> 
> "instance method"
> restoreAndProvideHistory
>     | result |
>     "Extract information before mutating because it won't be available
> afterwards."
>     result := history.
>     self become: object.
>     ^ result.
> 
> Here's an example of using this:
> 
> date := Date today.
> HistoryProxy on: date.
> date monthName print.
> date dayOfWeekName print.
> date year print.
> history := date restoreAndProvideHistory.
> history print "an OrderedCollection(monthName dayOfWeekName year)"
> 
> -- 
> R. Mark Volkmann
> Object Computing, Inc.

> -- 
> Cuis-dev mailing list
> Cuis-dev at lists.cuis.st
> https://lists.cuis.st/mailman/listinfo/cuis-dev



More information about the Cuis-dev mailing list