On Mon, May 22, 2017 at 3:25 PM, Luc Fabresse <[email protected]>
wrote:
> Hi,
>
> Following Pharo Days, I brainstormed about some possible class definition
> syntaxes.
> What I have in mind:
>
> "basic mechanics, only THIS one in the image!"
> ClassDefinition new
> superclass: Object; "optional. If not specified, Object by default ;-)"
> name: #A; "optional and create an anonymous class if not specified"
> instVars: 'a b c';
> traits: {TEquality};
> package: 'Plop';
> createClass. " this message sent might be hidden by the browser when
> accepting"
>
> "---------------"
> "Some IDEAS (but I did not find one that I really like) of
> scripting/shorter syntaxes that must ALWAYS end up calling the above basic
> mechanics at the end:"
>
> Class fromDefinition: [ :def |
> def name: #sub;
> instVars: 'w r g';
> superclass: Object ].
>
> Object subclass "<-- returns a subclass of Object but the problem is that
> the new class is muted
>
(btw, I assume you mean mutated.)
> each time and the class definition is not explicit"
> name: #A;
> ivs: 'a b c';
> traits: { TEquality }.
>
What about...
Object subclass: [ :def | def
name: 'MyClass' ; "optional and create an anonymous class if not
specified"
instanceVariables: 'a b c' ;
classVariables: 'M N O';
classInstanceVariables: 'x y z' ;
traits: {TEquality} ;
package: 'Plop'].
Object>>subclass: builderBlock
^ (builderBlock value: ClassDefinition new) createClass
or similar to Guille's declarative proposal...
Object subclass: {
name: 'Myclass',
a: InstVar,
b: InstVar,
c: InstVar
}
cheers -ben