Skip to content

Instantly share code, notes, and snippets.

@colomon
Created December 13, 2011 16:39
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/1472831 to your computer and use it in GitHub Desktop.
Save colomon/1472831 to your computer and use it in GitHub Desktop.
Suggested broad cmp algorithm:
infix:<cmp>($a, $b) {
if $a ~~ Numeric && $b ~~ Numeric { return $a <=> $b }
if $a ~~ Stringy && $b ~~ Stringy { return $a leg $b }
if $a ~~ Positional && $b ~~ Positional { return [||] (@$a Zcmp @$b) }
if $a ~~ Hash && $b ~~ Hash { maybe? dunno how to do this }
$a.WHAT leg $b.WHAT; # except it has to handle the two different classes with the same name case
}
Take two, with TimToady and benabik input:
infix:<cmp>($a, $b) {
if $a ~~ cmp(positionalish) || $b ~~ cmp(positionalish) { return || }
if $a ~~ cmp(Real) && $b ~~ cmp(Real) { return $a <=> $b }
if $a ~~ cmp(Unicode) && $b ~~ cmp(Unicode) { return $a leg $b }
if $a ~~ cmp(hashish) && $b ~~ cmp(hashish) { maybe? dunno how to do this }
$a.WHAT leg $b.WHAT; # except it has to handle the two different classes with the same name case
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment