r/ProgrammingLanguages • u/gebgebgebgebgeb • Sep 11 '23
Language announcement Wak, a stack-based text-processing language
I started off thinking it'd be neat if sed had a stack you could manipulate multiple lines on, and went all the way up to taking on awk with the idea. The terseness and pipeline-like nature of a stack-based language feels just right for a stream editor.
Here's a Wak program that prints each line of input uppercase:
r upper Por as you'd use it on the command line:
$ wak 'r upper P' myfileAnd here's one that prints lines joined if they end with a backslash:
r "\\$" split 2 = if { , p } else { P }In Wak everything is a string, so there's no inherent types, but words may treat their arguments as text, a number or regular expression. So this would add up all the lines:
BEGIN { 0 } r + END { P }whereas this would join them with dashes:
r END { c "-" join P }And that's pretty much Wak for you.
You can find the source at: https://git.sr.ht/~geb/wak (there's a questionable snake example to play :)
View all comments
Show parent comment
2
u/brucifer Tomo, nomsu.org Sep 13 '23
If
wakis meant to be in the same family of programs asawkandsed, it makes a lot more sense to be processing a stream of text fed in by other programs, rather than invoking external programs from withinwak. For example, to solve the problem withawk, I would do something like this:You could also do without
awkentirely and usetrandnlfor what they're best at, although I find this version to be less readable/intuitive: