19.11.2014 Views

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

38.2 <strong>The</strong> Trait <strong>Fortress</strong>.Standard.TotalComparison<br />

<strong>The</strong> comparison operator CMP , when applied to values belonging to a total order, typically returns a value of type<br />

TotalComparison. <strong>The</strong> three values of type TotalComparison are called LessThan, EqualTo, and GreaterThan.<br />

This trait supports an associative operator LEXICO that is useful for supporting lexicographic comparison of ordered<br />

sequences; the trick is to compare the sequences elementwise and then to use the LEXICO operator to reduce the<br />

sequence of comparison results. Note that EqualTo is the identity for LEXICO , and all other comparison values are<br />

left zeroes for LEXICO .<br />

value trait TotalComparison<br />

extends { Comparison,<br />

AssociativeTotalComparison,LEXICO,<br />

HasIdentityTotalComparison,LEXICO,<br />

HasLeftZeroesTotalComparison,LEXICO,isLeftZeroForLEXICO }<br />

comprises { LessThan, EqualTo, GreaterThan }<br />

opr LEXICO(self,other: TotalComparison): TotalComparison<br />

isLeftZeroForLEXICO(self):Boolean<br />

opr =(self,other: TotalComparison): Boolean<br />

getter hashCode(): Z64<br />

toString():String<br />

end<br />

LessThan: TotalComparison<br />

EqualTo: TotalComparison<br />

GreaterThan: TotalComparison<br />

38.2.1 opr LEXICO(self,other: TotalComparison):TotalComparison<br />

<strong>The</strong> operator LEXICO returns its right argument if the left argument is EqualTo; otherwise it returns its left argument.<br />

<strong>The</strong> LEXICO operator as applied to total comparison values may be described by this table:<br />

LEXICO LessThan EqualTo GreaterThan<br />

LessThan LessThan LessThan LessThan<br />

EqualTo LessThan EqualTo GreaterThan<br />

GreaterThan GreaterThan GreaterThan GreaterThan<br />

38.2.2 isLeftZeroForLEXICO(self):Boolean<br />

This method returns false for EqualTo and true for all other total comparison values.<br />

38.2.3 opr =(self,other: TotalComparison):Boolean<br />

Two total comparison values are strictly equivalent if and only if they are the same.<br />

266

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!