Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,49 @@
fcn nestToIndent(nestTree){
fcn(out,node,level){
out.append(List(level,node[0])); // (n,name) or ("..",name)
if(node.len()>1){ // (name children), (name, (tree))
level+=1;
foreach child in (node[1,*]){
if(String.isType(child)) out.append(List(level,child));
else self.fcn(out,child,level)
}
}
out
}(List(),nestTree,0)
}
fcn nestToString(nestTree,dot="."){
fcn(out,dot,node,level){
out.writeln(dot*level,node[0]); // (name)
if(node.len()>1){ // (name children), (name, (tree))
level+=1;
foreach child in (node[1,*]){
if(String.isType(child)) out.writeln(dot*level,child);
else self.fcn(out,dot,child,level)
}
}
out
}(Data(),dot,nestTree,0).text
}
fcn indentToNest(iTree,depth=0,nTree=List()){
while(iTree){ // (n,name)
d, name := iTree[0];
if(d==depth){
nTree.append(name);
iTree.pop(0);
}
else if(d>depth){ // assume can't skip levels down
if(nTree.len()>1 and not List.isType((nm:=nTree[-1]))){
nTree[-1]=(children:=List(nm));
indentToNest(iTree,d,children);
}else{
nTree.append(children:=List(name));
iTree.pop(0);
indentToNest(iTree,d+1,children);
}
}
else break; // d<depth
}
return(nTree)
}
fcn indentToString(indentTree){ indentTree.apply("concat"," ").concat("\n") }

View file

@ -0,0 +1,13 @@
tree:=L("RosettaCode",
L("rocks","code","comparison","wiki"),
L("mocks","golfing") );
println("Nest tree internal format:\n",tree.toString(*,*));
println("Formated:\n",nestToString(tree));
indentTree:=nestToIndent(tree);
println("To indent format:\n",indentToString(indentTree));
nestTree:=indentToNest(indentTree);
println("\nIndent to nested format:\n",nestTree);
println("Is this tree the same as what we started with? ",nestTree==tree);

View file

@ -0,0 +1,17 @@
rakutrees:=L(
L("RosettaCode",
L("encourages",
L("code",
"diversity","comparison")),
L("discourages",
"golfing","trolling","emphasising execution speed"),
),
L("code-golf.io",
L("encourages","golfing"),
L("discourages","comparison"),
)
);
println(rakutrees.apply(nestToString).concat());
iTrees := rakutrees.apply(nestToIndent);
println(iTrees.apply(indentToString).concat("\n"));
(iTrees.apply(indentToNest)==rakutrees).println();