September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
|
|
@ -1,67 +1,64 @@
|
|||
import system'routines.
|
||||
import extensions.
|
||||
import system'routines;
|
||||
import extensions;
|
||||
|
||||
class Node
|
||||
{
|
||||
object theValue.
|
||||
object theChildren.
|
||||
string theValue;
|
||||
Node[] theChildren;
|
||||
|
||||
constructor new : value children:children
|
||||
[
|
||||
theValue := value.
|
||||
constructor new(string value, Node[] children)
|
||||
{
|
||||
theValue := value;
|
||||
|
||||
theChildren := children toArray.
|
||||
]
|
||||
theChildren := children;
|
||||
}
|
||||
|
||||
constructor new : value
|
||||
<= new:value children:nil.
|
||||
constructor new(string value)
|
||||
<= new(value, new Node[](0));
|
||||
|
||||
constructor new children:children
|
||||
<= new:emptyLiteralValue children:children.
|
||||
constructor new(Node[] children)
|
||||
<= new(emptyString, children);
|
||||
|
||||
constructor new : value child:child
|
||||
<= new:value children(Array new object:child).
|
||||
get() = theValue;
|
||||
|
||||
get = theValue.
|
||||
|
||||
children = theChildren.
|
||||
Children = theChildren;
|
||||
}
|
||||
|
||||
extension treeOp
|
||||
{
|
||||
writeTree : node : prefix : childrenProp
|
||||
[
|
||||
var children := node~childrenProp get.
|
||||
var length := children length.
|
||||
writeTree(node, prefix)
|
||||
{
|
||||
var children := node.Children;
|
||||
var length := children.Length;
|
||||
|
||||
children zip(RangeEnumerator new from:1 to:length) forEach(:child:index)
|
||||
[
|
||||
self printLine(prefix,"|").
|
||||
self printLine(prefix,"+---",child get).
|
||||
children.zipForEach(new Range(1, length), (child,index)
|
||||
{
|
||||
self.printLine(prefix,"|");
|
||||
self.printLine(prefix,"+---",child.get());
|
||||
|
||||
var nodeLine := prefix + (index==length)iif(" ","| ").
|
||||
var nodeLine := prefix + (index==length).iif(" ","| ");
|
||||
|
||||
self writeTree(child,nodeLine,childrenProp).
|
||||
].
|
||||
self.writeTree(child,nodeLine);
|
||||
});
|
||||
|
||||
^ self.
|
||||
]
|
||||
^ self
|
||||
}
|
||||
|
||||
writeTree : node : childrenProp
|
||||
= self~treeOp writeTree(node,"",childrenProp).
|
||||
writeTree(node)
|
||||
= self.writeTree(node,"");
|
||||
}
|
||||
|
||||
program =
|
||||
[
|
||||
var tree := Node new children:
|
||||
(
|
||||
Node new:"a" children:
|
||||
(
|
||||
Node new:"b" child:(Node new:"c"),
|
||||
Node new:"d"
|
||||
),
|
||||
Node new:"e"
|
||||
).
|
||||
public program()
|
||||
{
|
||||
var tree := Node.new(
|
||||
new Node[]{
|
||||
Node.new("a", new Node[]
|
||||
{
|
||||
Node.new("b", new Node[]{Node.new("c")}),
|
||||
Node.new("d")
|
||||
}),
|
||||
Node.new("e")
|
||||
});
|
||||
|
||||
console writeTree(tree, %children); readChar.
|
||||
].
|
||||
console.writeTree(tree).readChar()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue