Make awk rawk
A friend online recently replied to something I wrote about awk by saying:
[…] it’s a danged shame [awk] didn’t continue to evolve the way Ruby, Python, PHP have evolved over the decades.
I had exactly this thought while working on my slightly unhinged “lets see if I can implement a basic scheme using awk by writing an assembler and VM in awk,” skwak. Which eventually lead me to start noodling on how to layer in some modern niceties into awk, without breaking awk’s portability.
Enter my efforts to make awk rawk!
Depending on who you ask rawk is either a compiler or a preprocessor for awk, implemented in POSIX awk. It allows you to write declarative, functional-flavored code, with support for first-class functions, operations like map and reduce, and a standard library for what I reckon to be some of the things awk is mostly used for (though I’d love to hear about what you use it for, and if the standard library could use any additional utilities or predicates).
The feature I’m most proud of, though, are the result types. The semantics are inspired by what little I know about rust’s Result, and allow you to do stuff like:
RAWK {
$to_number = (s) -> {
if (is_number(s)) {
return Ok(s + 0); # Success!
}
return Err("value is not a number"); # Failure!
};
}
I’m pretty excited about it, and have had a lot of fun implementing this project.
The readme and the tutorial cover most of what you need to know to get started, but don’t hesitate to reach out if you have questions or ideas for rawk.
Published