2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -0,0 +1,62 @@
#import system.
#import system'routines.
#import extensions.
#class Node
{
#field theValue.
#field theChildren.
#constructor new : value &children:children
[
theValue := value.
theChildren := children toArray.
]
#constructor new : value
<= new:value &children:nil.
#constructor new &children:children
<= new:emptyLiteralValue &children:children.
#constructor new : value &child:child
<= new:value &children:(Array new &object:child).
#method get = theValue.
#method children = theChildren.
}
#class(extension)treeOp
{
#method writeTree:node:prefix &subject: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:" ":"| ".
self writeTree:child:nodeLine &subject:childrenProp.
].
^ self.
]
#method writeTree:node &subject:childrenProp
= self writeTree:node:"" &subject:childrenProp.
}
#symbol program =
[
#var tree := Node new &children:
(
Node new:"a" &children:
(
Node new:"c" &child:(Node new:"d"),
Node new:"d"
),
Node new:"b").
console writeTree:tree &subject:%children.
].