I'm trying to understand the syntax of GNU Smalltalk class definitions.
https://www.gnu.org/software/smalltalk/manual/html_node/The-syntax.html documents the BNF of the bang syntax: methods: ``!'' id [``class''] ``methodsFor:'' string ``!'' [method ``!'']+ ``!'' But for the "new style" syntax, I can't see how it fits. From the BNF point of view, it looks pretty much like a method call, but not quite. More specifically I thought that in Smalltalk [...] is just a block (aka closure). So how does Smalltalk know that when I do Package extend [ ... ] this [...] should not be a block (or is it still treated as a block, except that "Package extend" then uses introspection to look inside the body of the closure and analyze its "source code" to treat it as something different)? Better yet: my current understanding of Smalltalk syntax tells me that "Package extend" is a method invocation with the unary selector "extend", i.e. it's (Package extend) [ ... ] so what is the "operation" that passes [ ... ] to (Package extend)? I doesn't look like any of the three syntaxes of method invocation I know (unary, binary, and multiple-keywords)? Stefan _______________________________________________ help-smalltalk mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-smalltalk |
Stefan Monnier writes: > Better yet: my current understanding of Smalltalk syntax tells me that > "Package extend" is a method invocation with the unary selector > "extend", i.e. it's > > (Package extend) [ ... ] > > so what is the "operation" that passes [ ... ] to (Package extend)? > I doesn't look like any of the three syntaxes of method invocation > I know (unary, binary, and multiple-keywords)? > keyword to indicate this special construct. Derek _______________________________________________ help-smalltalk mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-smalltalk |
> 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`? What about the case of "C1 :subclass C2 [...]", is "subclass:" also a reserved keyword? Does it also prevent using method called `:subclass`? What about uses of `extend` or `subclass:` elsewhere than at top-level? 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? why do we need both the `class` and the `>>` keywords to define those class methods? Are there other possible valid elements than those two? Where is this documented (other than by showing examples)? Stefan _______________________________________________ help-smalltalk mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-smalltalk |
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? > > 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 :) _______________________________________________ help-smalltalk mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-smalltalk |
Free forum by Nabble | Edit this page |