Chomik Placeholders: Elegant Iteration Without Loops

Pawel BiernackiPawel Biernacki
3 min read

One of the more intriguing features of the Chomik programming language is the way it handles iteration — or more precisely, the fact that it doesn’t use explicit loops at all. Instead, Chomik uses placeholders, a concise yet powerful construct that lets you define implicit iteration over collections of values.

But let’s take a step back.


Collections in Chomik

Chomik allows you to define collections of values — sequences of data items — of any type it supports. This includes not only literals like numbers and strings, but also identifiers, which play a central role in the language.

In this article, we won’t delve into how to define your own collections just yet. For now, we’ll make use of a handy built-in collection: the boolean type. This is a collection of two identifiers: false and true.


Meet the Placeholders

Placeholders in Chomik act like temporary variables drawn from a collection. You can use them in variable names anywhere you’d normally use an identifier or a literal. Here’s a simple example:

<print (A:boolean)>;

This tells Chomik to iterate over all values in the boolean collection, temporarily assigning each to the placeholder A, and print the result. When executed, the output is:

false
true

If you're familiar with C++, this is roughly equivalent to:

for (A : vector_of_booleans)
{
std::cout << A << std::endl;
}

But in Chomik, we don't need an explicit for loop. The iteration is implied by the use of the placeholder syntax.


Cartesian Products with Placeholders

Things get even more interesting when you use multiple placeholders. For example:

<print (A:boolean) (B:boolean)>;
This line of code creates an implicit nested loop over the Cartesian product of boolean by itself, which is boolean × boolean. The output will be:

false false
false true
true false
true true

This is equivalent to the following C++ code:
for (A : vector_of_booleans)
{
for (B : vector_of_booleans)
{
std::cout << A << " " << B << std::endl;
}
}

So far, it looks like we’ve just replaced C++-style nested loops with a more compact and elegant syntax.


Shared Placeholders: Controlling the Iteration

Here’s where Chomik’s approach really starts to shine. What happens if you use the same placeholder multiple times?

<print (A:boolean) (A:boolean)>;

Chomik will recognize that A refers to the same placeholder, and instead of producing four pairs from boolean × boolean, it will only iterate once — matching each value with itself:

false false
true true
In other words, this is no longer a Cartesian product. It’s more like a diagonal of the Cartesian square.

Want something trickier?

<print (A:boolean) (B:boolean) (A:boolean)>;
Here, we define two placeholders — A and B — and then refer to A again. The output will be:

false false false
false true false
true false true
true true true

Why? Because the first and last A refer to the same value. So while the engine iterates over all combinations of A and B, each printed line uses the current value of A twice.


A World Without Loops?

It may sound bold, but in Chomik, there is no need for traditional looping constructs. Instead, the language relies on placeholders and evaluation over collections. By specifying sets and placeholder names, you describe the data you want to iterate over, and Chomik takes care of the rest — seamlessly and implicitly.

You’re not writing loops — you’re describing structure.

And that’s one of the beautiful things about Chomik.


What’s Next?

In future articles, we’ll explore how to define your own collections, use more advanced types, and combine placeholders with Chomik’s dynamic variable naming system. For now, feel free to play around with boolean and experiment with how placeholders behave. The more you explore, the more natural it becomes.

Welcome to a new way of thinking about iteration.



0
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.