Jump to content

Category:TXR: Difference between revisions

→‎What's with all that @ stuff?: Revise with up-to-date info.
(→‎What's with all that @ stuff?: Revise with up-to-date info.)
Line 27:
In TXR Lisp, the <code>@</code> character has more "meta" piled on top of it: <code>@foo</code> denotes <code>(sys:var foo)</code>, and <code>@(foo ...)</code> denotes <code>(sys:expr foo>)</code>. 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 <code>op</code> operator for currying, for instance <code>(op * @1 @1)</code> returns a function of one argument which returns the square of that argument. The implementation of the operator looks for syntax like <code>(sys:var 1)</code> and replaces it with the arguments of the generated lambda function. The <code>@</code> 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". Originally, ItTXR doesn'trecognized takeonly muchone tokind reachof thesource Lisp thoughfile: aone written in the TXR sourcelanguage. fileModern canTXR justrecognizes consistfiles ofwith a<code>.txr</code> singleand </code>.tl</code>@(do suffixes. <code>..)tl</code> directivefiles whichcontain contains nothing butjust TXR Lisp forms. Also "Hash bang" interpreter programs can be written in either language, without a suffix on the executable script file. TXR Lisp expression evaluation is also available from program invocation via the <code>-e</code> and <code>-p</code> options.
 
The second unusual feature in TXR 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 <code>@(collect :vars (foo))</code>. 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. ITIt begins a collect clause, and is followed by some optional material which may just be literal text, and must be terminated by the <code>@(end)</code> directive:, which is another token-expression entity.
 
=== Dual Personality ===
543

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.