sub fringe (\$tree) { # \$tree is aliased to \$a passed # by the fringe(\$a) call below. multi sub fringey (Pair \$node) # multi sub means other sub defs # will use the same sub name. # Pair is a builtin type. # It's like a one element hash. # \$node is "type constrained" - # it may only contain a Pair. { fringey \$_ for \$node.kv } # .kv is a method that returns # (key, value) of a Pair. # fringey is called twice, with # key as arg then value as arg. # If arg is a Pair, call this # fringey recursively. If not, # call sub fringey(Any \$leaf). multi sub fringey (Any \$leaf) # Each multi sub def must have a # different signature (params). # This def's param has Any type. { take \$leaf } # take yields a value that is # added to a gather'd list. (gather fringey \$tree), Cool; # This gather lazily gathers a # list yielded by take \$leaf's. # Calls to fringe return a list. # Cool is a flavor of undef. } sub samefringe (\$a, \$b) # \$a and \$b are binary trees # built from Pairs eg: # \$a = 1=>((2=>3)=>(4=>5)); # \$b = 1=>2=>(3=>4)=>5; # \$c = 1=>2=>(4=>3)=>5; # samefringe(\$a,\$b) # True # samefringe(\$a,\$c) # False { all # Builtin "all" returns True if # all following items are True. # Parallelizes & short-circuits. fringe(\$a) Z=== # === returns True if its LHS # and RHS are the same value. # Z is the zipwith metaop. # Z=== does === between each of # the items in the LHS list with # each of those in the RHS list. fringe(\$b) } }