Chomik: Comparing Integers


In previous articles, we explored some of Chomik’s built-in types, such as boolean
. Today, we’ll reveal another one — compare_result
— which is used when comparing integers.
The compare_result
type
The compare_result
type consists of exactly three identifiers:
lower
equal
greater
You can see them for yourself by printing the entire set:
<print (X:compare_result)>;
When you run this code, you’ll get:
lower
equal
greater
These values are used to indicate the outcome of a comparison.
Comparing two integers
To compare integers in Chomik, you use a built-in code variable whose name begins with compare “integer”
.
Here’s an example. Let’s compare the value of variable x
with the integer 1000
:
let x = value integer 123;
<compare "integer" <x> 1000>;
<print <the compare result>>;
Here’s what’s going on:
x
is assigned the integer value123
.<compare "integer" <x> 1000>
performs the comparison.The result is stored in the predefined variable
the compare result
, which is of typecompare_result
.Finally, we print the comparison result.
In this case, the output will be lower
.
Acting on comparison results
Since the compare result is just another variable, you can use it dynamically. A common pattern in Chomik is to define code variables for each possible outcome:
variable my reaction to (C:compare_result):code;
let my reaction to lower = value code { <print "it was lower!">; };
let my reaction to equal = value code { <print "it was equal!">; };
let my reaction to greater = value code { <print "it was greater!">; };
let x = value integer 123;
<compare "integer" <x> 1000>;
<my reaction to <the compare result>>;
How it works:
We declare a variable family
my reaction to (C:compare_result)
, meaning there will be a different code block for each oflower
,equal
, andgreater
.We define what happens in each case by assigning a block of code.
After comparing, we execute the corresponding block by calling
<my reaction to <the compare result>>
.
Why this is powerful
Instead of writing long if
or switch
statements, Chomik uses its dynamic variable naming feature to select the correct behavior directly. This makes code cleaner, more modular, and easier to extend — especially in cases where there might be many possible outcomes.
Subscribe to my newsletter
Read articles from Pawel Biernacki directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Pawel Biernacki
Pawel Biernacki
I was born in 1973, in Cracow, Poland. I am a software engineer.