September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -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.
|
||||
].
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ sub visualize-tree($tree, &label, &children,
|
|||
:@end = ('└─', ' '),
|
||||
) {
|
||||
sub visit($node, *@pre) {
|
||||
gather {
|
||||
| gather {
|
||||
take @pre[0] ~ label($node);
|
||||
my @children := children($node);
|
||||
my $end = @children.end;
|
||||
|
|
|
|||
20
Task/Visualize-a-tree/Zkl/visualize-a-tree.zkl
Normal file
20
Task/Visualize-a-tree/Zkl/visualize-a-tree.zkl
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
fcn vaultDir(out=Console){
|
||||
const INDENT=" ";
|
||||
space:=""; lastPath:=L();
|
||||
foreach fullname in (TheVault.BaseClass.contents.sort()){
|
||||
path:=fullname.split("."); name:=path.pop();
|
||||
if(lastPath==path) out.writeln(space,name);
|
||||
else{
|
||||
n:=0; p:=path.copy();
|
||||
try{
|
||||
while(path[0]==lastPath[0])
|
||||
{ n+=1; path.pop(0); lastPath.pop(0); }
|
||||
}catch{}
|
||||
space=INDENT*n;
|
||||
foreach dir in (path){ out.writeln(space,dir); space+=INDENT; }
|
||||
out.writeln(space,name);
|
||||
lastPath=p;
|
||||
}
|
||||
}
|
||||
"" // so startup has something to display
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue