Category:TXR

Revision as of 01:30, 25 January 2014 by Kazinator (talk | contribs) (Shorted the much too-long description. Expand slightly on the "anatomy".)
This page is a stub. It needs more information! You can help Rosetta Code by filling it in!
Language
TXR
This programming language may be used to instruct a computer to perform a task.
Official website
See Also:


Listed below are all of the tasks on Rosetta Code which have been solved using TXR.

TXR is a new language implemented in C, running on POSIX platforms such as Linux, Mac OS X and on Windows via Cygwin as well as more natively thanks to MinGW.

TXR started as a language for "reversing here-documents": evaluating a template of text containing variables, plus useful pattern matching directives, against some body of text and binding pieces of the text which matches variables. The variable bindings were output in POSIX shell variable assignment syntax, allowing for shell code like

eval $(txr <txr-program> <args> ...)

TXR remains close to these roots: its main language is the pattern-based text extraction notation well suited for matching large regions of entire text documents.

What's with all that @ stuff?

About the @ character: this serves as a multi-level escape in TXR. In the fundamental TXR syntax, which is literal text, this character is a signal which indicates that the object which follows is a variable or directive. Then inside a directive, the character indicates that the object which follows is a TXR Lisp expression to be evaluated as such, rather than according to the expression evaluation rules of the pattern language:

This is some literal text to be matched.
This text matches and binds @variable.
@(require  ;; this is the start of a directive in the TXR matching language
   @(> x 42) ;; this is an expression in TXR Lisp
)@# This is a comment in the pattern language.
Back to text.

In TXR Lisp, the @ character has more "meta" piled on top of it: @foo denotes (sys:var foo), and @(foo ...) denotes (sys:expr foo>). In any context which needs to separate meta-variables and meta-expressions from variables and expressions, this may come in handy. It's used by the op operator for currying, for instance (op * @1 @1) returns a function of one argument which returns the square of that argument. The implementation of the operator looks for syntax like (sys:var 1) and replaces it with the arguments of the generated lambda function. The @ character also appears in quasiliteral strings, where it interpolates the values of variables and expressions as text.

TXR is somewhat unusual in that the relationship between a domain-specific language (DSL) and general-purpose host language is reversed. Typically, at least in Lisp systems, DSL's are embedded into the parent language. In TXR, the "outer shell" is the domain-specific language for extracting text, and Lisp is embedded in it as "computational appliance". It doesn't take much to reach the Lisp though: a TXR source file can just consist of a single @(do ...) directive which contains nothing but TXR Lisp forms. Also, TXR Lisp evaluation is available from program invocation via the -e and -p options.

The second unusual feature in TXR Lisp is that the "tokens" in the pattern matching language are essentially themselves Lisp symbols and expressions. These "tokens" are used to create a block-structured language. This is quite odd. For instance a construct might begin with a @(collect :vars (foo)). This is a Lisp expression with interior structure, but to the parser of the pattern language, it's also basically just a token, like a giant keyword. IT begins a collect clause, and is followed by some optional material which may just be literal text, and must be terminated by the @(end) directive: another token-expression entity.

Subcategories

This category has the following 3 subcategories, out of 3 total.

Pages in category "TXR"

The following 160 pages are in this category, out of 160 total.