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.
par Mansour Ayouni · dans le dépôt depuis le 2024-12-13 · essai de conception · domaine Collections et objets
Cet article est écrit en anglais, comme la bibliothèque.


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:
load "stzlib.ring" ? @N(3, ".") #--> [ ".", ".", "." ] ? @NXT(3, ".", :InAList) #--> [ ".", ".", "." ] ? @NXT(3, ".", :InAString) #--> "..."
exécuté le 2026-10-08 20:42 au commit 4a184e6f0 : a tenu sa promesse
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:
? Three(".")
#--> [ ".", ".", "." ]exécuté le 2026-10-08 20:42 au commit 4a184e6f0 : a tenu sa promesse
And for brevity’s sake, Softanza offers the charmingly compact @3("."):
? @3(".")
#--> [ ".", ".", "." ]exécuté le 2026-10-08 20:42 au commit 4a184e6f0 : a tenu sa promesse
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 alternativesOne()toTen().
The Power of Intuitive Queries: StartsWith(), EndsWith(), and Beyond
Softanza makes querying strings and lists feel almost conversational:
? Q([ ".", ".", ".", "Tunis" ]).StartsWith( @3(".") )
#--> TRUE
? Q("...Tunis").StartsWith("...")
#--> TRUE
? Q("...Tunis").StartsWithXT( @3(".") )
#--> TRUEexécuté le 2026-10-08 20:42 au commit 4a184e6f0 : a tenu sa promesse
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():
? Q("Tunis..").EndsWithXT( @2(".") )
#--> TRUEexécuté le 2026-10-08 20:42 au commit 4a184e6f0 : a tenu sa promesse
NOTE:
StartsWith()andEndsWith()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:
? Q("...Tunis..").StartsWithXTQ( @3(".") ).AndQ().EndsWithXT( @2(".") )
#--> TRUEexécuté le 2026-10-08 20:42 au commit 4a184e6f0 : a tenu sa promesse
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.
Citer
Mansour Ayouni. « Repetition with Elegance: Exploring @N() and @NXT() Smart Builders in Softanza ». Softanza narrations, 2024. https://mayouni.github.io/stzsite/fr/narrations/stz-repetition-with-elegance-narration.html
Exécuté au nom de Haro le 2026-10-08 20:42 dans la bibliothèque au commit 4a184e6f0, bloc après bloc dans un seul processus : 6 bloc(s) sur 6 ont tenu leur promesse ; les autres sont des illustrations. Le code des articles est du code Haro. Là où un article a été écrit avant que la langue prenne son nom actuel, le nom a été changé et rien d'autre. Genre, domaine et série lus dans le nom du fichier, année tirée du premier commit : dérivés, jusqu'à ce que l'article porte son propre en-tête. Le fichier sur GitHub(s'ouvre dans un nouvel onglet)

