WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: txr - comparison may be drawn between the TXR Pattern Language and awk  (Read 45 times)

Offline mocore

  • Hero Member
  • *****
  • Posts: 662
  • ~.~

 TXR: an Original, New Programming Language for Convenient Data Munging @  https://www.nongnu.org/txr/
Quote
Innovative, but with traditional roots

TXR is a fusion of many different ideas, a few of which are original, and it is influenced by many languages, such as Common Lisp, Scheme, Awk, M4, POSIX Shell, Prolog, Ruby, Python, Arc, Clojure, S-Lang and others.

TXR consists of two languages, which can be used separately or tangled together: the TXR Pattern Language, and TXR Lisp.

A comparison may be drawn between the TXR Pattern Language and the Unix utility Awk.
Both provide an implicit, convenient way of scanning input.
Whereas Awk implicitly reads a file, breaking it into records and fields which are accessible as positional variables,
TXR has quite a different way of making input handling implicit: namely via a nested, recursive pattern matching notation which binds variables.

This approach still handles delimited fields with relative convenience,
but generalizes into handling messy, loosely structured data, or data which exhibits different regularities in different sections, etc.

Constructs in TXR (the pattern language) aren't imperative statements, but rather pattern-matching directives: each construct terminates by matching, failing, or throwing an exception.
Searching and backtracking behaviors are implicit.
It has features like structured named blocks with nonlocal exits, structured exception handling, named pattern matching functions, and numerous other features. 
TXR's pattern language is powerful enough to parse grammars, yet simple to use in an ad-hoc way on trivial tasks.

Speaking of Awk, TXR in fact contains an implementation of Awk,

in the form of a Lisp macro, which brings us to the next topic.
...

...
  https://www.nongnu.org/txr/txr-lisp.html

some of which is tbh beyond me
 ???
Quote
The with-objects macro instantiates objects in a lexical scope, and calls their finalizers when their scope ends, enabling some aspects of the "RAII" idiom from the C++ language to be used in TXR Lisp.

a reply on SO to
"What is meant by Resource Acquisition is Initialization (RAII)" @ https://stackoverflow.com/questions/2321511/what-is-meant-by-resource-acquisition-is-initialization-raii/18054738#18054738
 has this to say
Quote
It's a really terrible name for an incredibly powerful concept, and perhaps one of the number 1 things that C++ developers miss when they switch to other languages. There has been a bit of a movement to try to rename this concept as Scope-Bound Resource Management, though it doesn't seem to have caught on just yet.

https://en.wikipedia.org/wiki/Resource_acquisition_is_initialization

/jargon
« Last Edit: December 23, 2024, 07:52:12 AM by mocore »