------Proposal 2 use text to define modules and classes---------
2)
defining modules and classes
First I would like to start to introduce a script which defines the modules
and classes..
MyFirstModule := << Module |
MyPoint := << Class
|
varX.
varY.
#x
^varX.
#y
^varY
#x:x
varX:= x.
#y:y
varY:= y.
#
>>
MyStorage:= << Class |
#storeInto:File
#loadFrom:File
#
>>
>>.
This far it is simple..
I use a construct definition << >>
to define anything in my system..
There are many different constructs
possible:
Module, Class but also Application or DeviceDriver or
Primitive.
These could all be meta-constructions.
You probably have some nice idea's too :-)
------Proposal 3a define inheritance by including behaviour---------
3)
defining imports and inheritance
The Classname<<>> construct defines extension within current
construct,
i.e. inheritance...
The identifier<<>> construct defines a local extension. Is
currently used for imports.
MySecondModule:= << Module |
import<<
MyFirstModule.
>>.
version:= 3;
MyStoredPoint:= <<Class|
MyPoint<<
>>.
MyStorage<<
#storeInto:File
File
writeVar:varX.
File
writeVar:varY.
#loadFrom:File
varX:= File
readVar.
varY:= File
readVar.
#
>>.
>>.
>>.
Some may notice that:
MyFirstModule<< >> could also be an
import definition..
------Proposal 3b define inheritance by extending
behaviour---------
The class can als be extended using a similar syntax
MyThirdModule:= << Module |
import<<
Math. MyFirstModule.
>>
MyPoint:<< "this is an extension"
MyStorage<< "I inherit from MyStorage
again"
#storeInto:File
File
writeVar:varX.
File
writeVar:varY.
#loadFrom:File
varX:= File
readVar.
varY:= File
readVar.
#
>>.
>>
Integer:<<
#@ y
|
newPoint |
newPoint:= MyStoredPoint
new.
newPoint x:self;
y:y.
^newPoint.
#
>>
>>
------Proposal 4 change grammar a bit for some
typedefinitions---------
I'll use the example below
//In my own language I use a slightly different sytnax which enables
typedefinitions..
//And even parametric types.
//I'll just add the
different syntax for the good of discussion..
//I wonder if anyone here
really cares about what characters are used for certain definitions,
//as
long they are usefull..
//
//
// MyPoint:=
<<Class|
// varX;
//
varY;
// "x":={ varX; }; #methods
are defined as blocks
// "x:" := { ?x | varX:= x;
}; # ? defines input, ! defines output
//
// "y":={ !result| result:= varY; };
// "y:":= { ?y | varY:= y;
};
//
// varZ: Double,Integer; # type
definitions..
// # anything
that implements Double or Integer can work
// count::
Integer32 =0; # strict type definition and
initialisation
//
// # I add a z here to show some more
options
//
// "z"(!d:Double,Integer):={ d:= varZ;
};
// "z: ?d:Double":= { varZ:= d;
};
//
// ":Point":= { Point newX: varX andY: varY; };
// #defines point as replacement if
necessary
// #often easier than inheritance..
//
//
>>
//
// #Since the types and methods are binded at runtime,
// # we can may constants in definitions too..
//
//
Integer:<<
// "factorial:?0":=
{1};
// "factorial:?n:Integer":= { n*(n-1) factorial;
}
// >>
//
//
Integer:<<
//
"divmod()":(?x:Integer;!div,!mod:Integer):= { div:= self//x; mod:= self\\x
};
// #call with: 5 divmod(?x:= 3;
resDiv:= div; resMod:= mod);
// >>
//
I don't know how to do such definitions in current smalltalk grammar.
I
thought of using @ for types.. and :: for output, but these symbols
differ
too much from other languages..
-----------------------------
These modules reduce a bit of complexity of modules and
behaviours (traits, inheritance).
The script of managing projects and fileIn.
The fflexible typesystem might add to speed and such..
I know the problems are not all solved yet, but it is just a
start.