Monday, June 23, 2014

<=> The Spaceship Operator

Perl was the first language to use <=> the Spaceship Operator.
Groovy is another language that supports it.
So does Ruby!

What does it do?
Instead of returning 1 (true) or 0 (false) depending on whether the arguments are equal or unequal, the spaceship operator will return 1, 0, or −1 depending on the value of the left argument relative to the right argument.

a <=> b :=
  if a < b then return -1
  if a = b then return  0
  if a > b then return  1

It's useful for sorting an array.

http://stackoverflow.com/questions/16600251/how-does-rubys-sort-method-work-with-the-combined-comparison-spaceship-operat

tuple
In mathematics, computer science, linguistics, and philosophy a tuple is an ordered list of elements. In set theory, an -tuple is a sequence of elements, where is a non-negative integer. There is only one 0-tuple, an empty sequence.

No comments:

Post a Comment