Skip to content

Instantly share code, notes, and snippets.

@colomon
Created January 3, 2012 03:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colomon/1553342 to your computer and use it in GitHub Desktop.
Save colomon/1553342 to your computer and use it in GitHub Desktop.
# in Rakudo you can't pass a Mu to where an Array is expected,
# so we add multis for explicit undefined values
multi sub mirror(Any:U $a, Any:U $b) { return True; } #OK not used
multi sub mirror(Any:U $a, @b) { return False; } #OK not used
multi sub mirror(@a, Any:U $b) { return False; } #OK not used
multi sub mirror(@first, @second) {
if (@first|@second == (Mu,)) {
return @first == @second ;
}
mirror(left(@first),right(@second)) and mirror(right(@first),left(@second))
}
ok mirror(Mu,Mu),"mirror works with empty trees"; # fails
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment