September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -1,62 +1,67 @@
#import system.
#import system'routines.
#import extensions.
import system'routines.
import extensions.
#class Node
class Node
{
#field theValue.
#field theChildren.
object theValue.
object theChildren.
#constructor new : value &children:children
constructor new : value children:children
[
theValue := value.
theChildren := children toArray.
]
#constructor new : value
<= new:value &children:nil.
constructor new : value
<= new:value children:nil.
#constructor new &children:children
<= new:emptyLiteralValue &children:children.
constructor new children:children
<= new:emptyLiteralValue children:children.
#constructor new : value &child:child
<= new:value &children:(Array new &object:child).
constructor new : value child:child
<= new:value children(Array new object:child).
#method get = theValue.
get = theValue.
#method children = theChildren.
children = theChildren.
}
#class(extension)treeOp
extension treeOp
{
#method writeTree:node:prefix &subject:childrenProp
writeTree : node : prefix : childrenProp
[
#var children := node::childrenProp get.
#var length := children length.
children zip:(RangeEnumerator new &from:1 &to:length) &eachPair:(:child:index)
[
self writeLine:prefix:"|".
self writeLine:prefix:"+---":(child get).
#var nodeLine := prefix + (index==length)iif:" ":"| ".
var children := node~childrenProp get.
var length := children length.
self writeTree:child:nodeLine &subject:childrenProp.
children zip(RangeEnumerator new from:1 to:length) forEach(:child:index)
[
self printLine(prefix,"|").
self printLine(prefix,"+---",child get).
var nodeLine := prefix + (index==length)iif(" ","| ").
self writeTree(child,nodeLine,childrenProp).
].
^ self.
]
#method writeTree:node &subject:childrenProp
= self writeTree:node:"" &subject:childrenProp.
writeTree : node : childrenProp
= self~treeOp writeTree(node,"",childrenProp).
}
#symbol program =
program =
[
#var tree := Node new &children:
var tree := Node new children:
(
Node new:"a" &children:
Node new:"a" children:
(
Node new:"c" &child:(Node new:"d"),
Node new:"b" child:(Node new:"c"),
Node new:"d"
),
Node new:"b").
console writeTree:tree &subject:%children.
Node new:"e"
).
console writeTree(tree, %children); readChar.
].