Created
August 21, 2012 23:52
-
-
Save KitWallace/3420598 to your computer and use it in GitHub Desktop.
invert a stick (a tree wih no branches) Challenge 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare function local:stick_to_seq($stick) { | |
if ($stick) | |
then (name($stick),local:stick_to_seq($stick/*)) | |
else () | |
}; | |
declare function local:seq_to_stick($seq) { | |
if (exists($seq)) | |
then element {$seq[1]} {local:seq_to_stick(subsequence($seq,2))} | |
else () | |
}; | |
declare function local:invert($stick) { | |
local:seq_to_stick(reverse(local:stick_to_seq($stick))) | |
}; | |
let $x := <a><b><c><d/></c></b>/</a> | |
return local:invert($x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment