Softanza
StartFrançais
Softanza
Research · narration

Repetition with Elegance: Exploring @N() and @NXT() Smart Builders in Softanza

In the hands of a painter, repetition is not mundane—it’s an art form. Each stroke, though seemingly similar, contributes to the greater beauty of the canvas. Similarly, in programming, crafting repetitive patterns can elevate code from functional to elegant.

by Mansour Ayouni · in the repository since 2024-12-13 · design essay · area Collections & objects

Repetition with Elegance in Softanza, by Microsoft Image AI
Repetition with Elegance in Softanza, by Microsoft Image AI

Repetition with Elegance in Softanza, by Microsoft Image AI


Introduction

Softanza’s dynamic repetition functions, such as @N(), @NXT(), and @3(), transform repetitive tasks into graceful brushstrokes of logic, enabling developers to create expressive and efficient solutions with minimal effort.

This article delves into these tools, exploring how Softanza empowers developers to shape repetitive sequences with the precision and beauty of an artist, while maintaining the practical utility required for real-world applications.

Meet the Dynamic Builders: @N() and @NXT()

Building repetitive patterns is often a tedious task. With Softanza, repetition becomes artistry:

Haro
load "stzlib.ring"

? @N(3, ".")
#--> [ ".", ".", "." ]

? @NXT(3, ".", :InAList)
#--> [ ".", ".", "." ]

? @NXT(3, ".", :InAString)
#--> "..."

run on 2026-10-08 20:42 at commit 4a184e6f0: kept its promise

Here, @N() and @NXT() create sequences of repeated characters with an optional format (:InAList or :InAString). Whether you need a list of dots for validation or a string of them for comparison, these utilities adapt seamlessly.

For developers who think in terms of semantics, the Three() function provides an alternative yet equally expressive way to generate the same output:

Haro
? Three(".")
#--> [ ".", ".", "." ]

run on 2026-10-08 20:42 at commit 4a184e6f0: kept its promise

And for brevity’s sake, Softanza offers the charmingly compact @3("."):

Haro
? @3(".")
#--> [ ".", ".", "." ]

run on 2026-10-08 20:42 at commit 4a184e6f0: kept its promise

NOTE: You can express any number of repetitions using @N(), and for convenience, there are shortcuts for repetitions from @1() to @10(), accompanied by their semantic alternatives One() to Ten().

The Power of Intuitive Queries: StartsWith(), EndsWith(), and Beyond

Softanza makes querying strings and lists feel almost conversational:

Haro
? Q([ ".", ".", ".", "Tunis" ]).StartsWith( @3(".") )
#--> TRUE

? Q("...Tunis").StartsWith("...")
#--> TRUE

? Q("...Tunis").StartsWithXT( @3(".") )
#--> TRUE

run on 2026-10-08 20:42 at commit 4a184e6f0: kept its promise

Here, the StartsWith() method works across different data structures, whether it’s a list or a string. The expressive StartsWithXT() variant further extends its capabilities, enabling dynamic pattern matching. The flexibility is striking: you can check if a string begins with a pattern defined at runtime without verbose logic.

The same logic applies to ending patterns, as seen with EndsWithXT():

Haro
? Q("Tunis..").EndsWithXT( @2(".") )
#--> TRUE

run on 2026-10-08 20:42 at commit 4a184e6f0: kept its promise

NOTE: StartsWith() and EndsWith() are just two examples among hundreds of powerful methods offered by Softanza for comprehensive string checking.

Chaining for Clarity: Combining Queries

Softanza elevates readability with its fluent query-chaining abilities. Consider this combined query:

Haro
? Q("...Tunis..").StartsWithXTQ( @3(".") ).AndQ().EndsWithXT( @2(".") )
#--> TRUE

run on 2026-10-08 20:42 at commit 4a184e6f0: kept its promise

Here, the query verifies whether a string starts with three dots and ends with two dots. The Q in each method transforms the output into a Softanza object, allowing seamless chaining of additional methods. The AndQ() method ensures fluid transitions between queries, creating a logical flow that reads naturally.

This design is particularly well-suited for validating complex conditions in data processing pipelines.

Practical Use Cases

  • Dynamic String Validation: Check if a user’s input repeats specific characters, such as ensuring an entry starts with three dots ("...") or ends with two underscores ("__").

  • Log Analysis: Identify logs with repetitive patterns, such as entries beginning with three stars ("***") to indicate priority events.

  • Template Processing: Validate templates that rely on repeated structures, like ensuring a header starts with three hyphens ("---") for separation.

  • Text Data Normalization: Ensure consistency by checking if dataset entries begin or end with specific repetitive patterns, like rows starting with two tabs ("\t\t") or ending with three periods ("...").

  • Interactive Pattern Matching: Enable real-time validation for fields requiring repetition, such as detecting prefixes of repeated symbols ("###") in formatted text editors.


Conclusion

Softanza’s string utilities, exemplified here, blend elegance with raw power. They transform mundane operations into delightful expressions of logic, empowering developers to craft solutions that are as beautiful as they are efficient.

Cite

Mansour Ayouni. "Repetition with Elegance: Exploring @N() and @NXT() Smart Builders in Softanza". Softanza narrations, 2024. https://mayouni.github.io/stzsite/en/narrations/stz-repetition-with-elegance-narration.html

Run in Haro's name on 2026-10-08 20:42 inside the library at commit 4a184e6f0, block after block in one process: 6 of 6 blocks kept their promise; the others are illustrations. The code of the articles is Haro code. Where an article was written before the language took its present name, the name was changed and nothing else. Genre, area and series read from the file's name, the year from its first commit: derived, until the article carries its own header. The file on GitHub(opens in a new tab)