Chomik: Integer Ranges


In the previous articles on this blog, we introduced the concept of placeholders in Chomik — a technique that allows us to execute code as if we had some kind of loop instruction. So far, our examples were mostly based on the boolean type, because it is built-in and easy to use without diving into type declarations.
In this article, I want to take you one step further and introduce something I call ad hoc types. These are types you can use directly without actually defining them. For now, this makes sense only for integer ranges. Let’s see how it works.
The Simplest Form
Here is the simplest possible example:
<print (X:1..10)>;
This prints all the integer values from 1
to 10
, line by line. As always in Chomik, you can also benefit from the Cartesian product of placeholders. For example:
<print (X:1..10) (Y:2..3)>;
This will print all pairs of values, combining every X
with every Y
.
Assignments with Ranges
The range syntax can also be used in assignments. If you’ve followed the earlier examples with booleans, this will look familiar. For instance:
let x (A:1..5) = value string "alpha";
This creates variables with the names x 1
, x 2
, ..., x 5
, each holding the string value "alpha"
.
Now, if we want to print the values of these variables, we can do it like this:
<print <x (C:1..5)> >;
Notice the difference: in this case we’re not printing the integers 1..5
directly, but instead the values of variables named x 1
, x 2
, ..., x 5
. Since all of them were assigned the same string, the output is simply:
alpha
alpha
alpha
alpha
alpha
Combining Assignments
Things get more interesting when we combine multiple assignments:
let x (A:1..5) = value string "alpha";
let x (B:2..3) = value string "beta";
let x 4 = value string "gamma";
<print <x (C:1..5)>>;
This will print:
alpha
beta
beta
gamma
alpha
Here’s what happens:
First, all
x 1
..x 5
are set to"alpha"
.Then
x 2
andx 3
are overwritten with"beta"
.Finally,
x 4
is overwritten with"gamma"
.
Why Ranges Only for Integers?
You might wonder: why allow this special ..
syntax only for integers? Isn’t it confusing to reuse the same syntax that worked with booleans?
The reason is that integers are countable. We can always generate all values in a finite range of integers, which makes them perfect for this ad hoc syntax. For example:
<print (X:3.14159..9.999)>;
This would be a syntax error, because floats are not countable — no matter how many values you print, infinitely many are missing.
Similarly:
<print (X:”alpha”..”beta”)>;
is invalid, because there is no meaningful way to generate all strings between "alpha"
and "beta"
.
Integers, on the other hand, fit perfectly. They give us a finite, enumerable set that integrates naturally with Chomik’s placeholder system.
Conclusion
Integer ranges are a simple but powerful feature of Chomik. They extend the placeholder mechanism beyond booleans, making it possible to:
Print sequences of numbers easily.
Generate Cartesian products of ranges.
Assign and manipulate families of variables in a compact way.
This feature also demonstrates one of the central ideas of Chomik: variable names themselves are part of the data structure, and placeholders — whether boolean, integer, or something else in the future — are a natural way to construct them.
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.