« Home » « Learn » « Download » « Github »

logo

Cello High Level C

Methods

cmp

int cmp(var self, var obj);

The return value of cmp is < 0 if self is less than obj, > 0 if self is greater than obj and 0 if they are equal.

eq

bool eq(var self, var obj);

Returns true if the object self is equal to the object obj.

neq

bool neq(var self, var obj);

Returns false if the object self is equal to the object obj.

gt

bool gt(var self, var obj);

Returns true if the object self is greater than the object obj.

lt

bool lt(var self, var obj);

Returns false if the object self is less than the object obj.

ge

bool ge(var self, var obj);

Returns false if the object self is greater than or equal to the object obj.

le

bool le(var self, var obj);

Returns false if the object self is less than or equal to the object obj.

Examples

Usage 1

show($I( eq($I(1), $I( 1)))); /* 1 */
show($I(neq($I(2), $I(20)))); /* 1 */
show($I(neq($S("Hello"), $S("Hello")))); /* 0 */
show($I( eq($S("Hello"), $S("There")))); /* 0 */

var a = $I(1); var b = $I(1);

show($I(eq(a, b))); /* 1 */
show($I(a is b));   /* 0 */
show($I(a isnt b)); /* 1 */

Usage 2

show($I(gt($I(15), $I(3 )))); /* 1 */
show($I(lt($I(70), $I(81)))); /* 1 */
show($I(lt($I(71), $I(71)))); /* 0 */
show($I(ge($I(78), $I(71)))); /* 1 */
show($I(gt($I(32), $I(32)))); /* 0 */
show($I(le($I(21), $I(32)))); /* 1 */

show($I(cmp($I(20), $I(20)))); /*  0 */
show($I(cmp($I(21), $I(20)))); /*  1 */
show($I(cmp($I(20), $I(21)))); /* -1 */

Cmp


Comparison

The Cmp class is used to define comparison between two object values. This class is important as it is used by many data structures to test equality or ordering of objects.

By default, if passed two objects of the same type, the Cmp class will simply compare the raw memory of both objects, using the Size class.

To implement this class a cmp function must be provided which returns < 0 if the first object is less than the second, > 0 if the first object is greater than the second, and 0 if they are equal.

For objects that manage their own data this class may need to be overridden to ensure that objects of the same value are still treated as equal. E.G. for string types.

This class to used to test for value equality between objects, I.E. if they represent the same thing. For object equality the is keyword can be used, which will return true only if two variables are pointing to the same object in memory.

Definition

struct Cmp {
  int (*cmp)(var, var);
};

Derivers

  • Box |     Unique Pointer
  • Exception |     Exception Object
  • File |     Operating System File
  • Filter |     Filtered Iterable
  • Function |     Function Object
  • GC |     Garbage Collector
  • Map |     Apply Function to Iterable
  • Mutex |     Mutual Exclusion Lock
  • Process |     Operating System Process
  • Ref |     Shared Pointer
  • Zip |     Multiple Iterator

Implementers

  • Array |     Sequential Container
  • Float |     Floating Point Object
  • Int |     Integer Object
  • List |     Linked List
  • Range |     Integer Sequence
  • Slice |     Partial Iterable
  • String |     String Object
  • Table |     Hash table
  • Thread |     Concurrent Execution
  • Tree |     Balanced Binary Tree
  • Tuple |     Basic Collection
  • Type |     Metadata Object

Back