[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Sample program



Danny Travis (danny@cs.ttu.edu) wrote:
> Bay sent me the following program to reverse a string of characters:
> 
> _AddSlotsIfAbsent: ( | danny = () | )
> 
> danny _Define: ( |
>     parent* = traits oddball.
> 
>     reverse: str = ( | rev <- '' |
>         str do: [ | :c | rev: c, rev ].
>         rev ).
> | )

The first line adds a slot called "danny" to the lobby.  The receiver
is "implicit self" and self is the lobby at the prompt.  Since there
is no asterisk on the slot name, the "reverse:" method inside "danny"
will not be inherited by the lobby.  Therefore, you must explicitly
ask for the "reverse:" method in "danny":

  danny reverse: 'backwards'

This is why you got a message not understood error: you sent the
message to the lobby (probably implicitly).  Of course, the reverse
method should probably have the string as a receiver rather than an
argument - Bay's code was meant to be non-intrusive.

The problem with using list methods I don't understand.  Details might
help.

Good to see someone using SELF...


Danny Epstein          grad(ual) student at Carleton U, Ottawa Canada
dje@scs.carleton.ca    Smalltalker and occasional SELFer.
80r2.5 > 80r4 > V/Win > V/Mac > V/286 > V/DOS > C = 0