help-smalltalk
[Top][All Lists]
Advanced

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

Re: [Help-smalltalk] Syntax of GNU Smalltalk class definitions


From: Derek Zhou
Subject: Re: [Help-smalltalk] Syntax of GNU Smalltalk class definitions
Date: Sat, 27 Apr 2019 15:24:20 +0800
User-agent: mu4e 0.9.18; emacs 25.1.1

Stefan Monnier writes:

>> This [ ... ] is not a block closure and the "extend" is more like a
>> keyword to indicate this special construct.
>
> "like"?  Is it a reserved keyword?  Does that mean you can't define
> a method called `extend`?
You can. However, under this circumstance (very top level) the parser does
treat it differently. 
>
> What about the case of "C1 :subclass C2 [...]", is "subclass:" also
> a reserved keyword?  Does it also prevent using method called
> `:subclass`?
subclass: is a method call. However, under this circumstance (very top
level) the parser is also recognizing the special construct as the body
of the class.

So in gst3 syntax to protect against these traps, if you do
want to have loose statements on the top level you will need to wrap
them in a Eval [ ... ] block; which is again a special construct only
valid at the top level.

>
> What about uses of `extend` or `subclass:` elsewhere than at top-level?
Then they lose the special treatment.
>
> Also within such a "set of methods", I see two different method
> definitions:
>
>     <method-selector> [<method-body>]
>     
> and
>
>     <class> class >> <method-selector> [<method-body>]
>     
> what happens if <class> is another class than the one for which this
> block is defining methods?
Theoretically you can; however I think it is not encouraged.
>
> why do we need both the `class` and the `>>` keywords to define those
> class methods?
Theoretically you can even write:
<class> >> <method-selector> [<method-body>]
where <class> is a different class. However it is also not encouraged
for obvious reason.
The >> seperates the owner of this method and the method itself. Without
it it looks really awkward.
The outer block in extend or subclass: only gives default owner of
methods.
>
> Are there other possible valid elements than those two?
Other than what have been menthoned, no. Actually you don't strictly
need the second form if you put all class methods in a:

<class> class extend [ ... ]

block. There is no special priviledge for method or class method defined
in the original subclass: block.
>
> Where is this documented (other than by showing examples)?
>
I was wondering the same :)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]