texmacs-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Texmacs-dev] Manual closures


From: Sam Liddicott
Subject: [Texmacs-dev] Manual closures
Date: Thu, 24 May 2012 08:25:23 +0100

I thought I'd try implementing closures in texmacs macros instead.

I want a macro that can be provided a list of variables and produce a new macro that is a "with" block of those variables, and then evaluates the parameters.

The produced macro would be of this form (although possibly I would use eval instead of compound):
<xmacro|x|<with|...|...|<quasi|<compound|<unquote*|<quote-arg|x>>>>>>

It seems it would work as this example shows:
<xmacro|x|<with|a|AHA|<quasi|<compound|<unquote*|<quote-arg|x>>>>>>

The producing macro must fill in ... according to the arguments it is passed, indicating the variables and their values to be preserved.

My first attempt at the constructing macro is:
<assign|enclose|<xmacro|w|<quasi|<xmacro|x|<quasi|<with|<unquote*|<quote-arg|w>>|<compound|<unquote*|<quote-arg|x>>>>>>>>>

Note the nested quasi. I need the first unquote* to be expanded by the first quasi, and the second quasi to be preserved along with the second unquote*, but nesting makes this hard, because the first quasi encloses the second quasi which encloses both unquote*

<assign|enclose|<xmacro|w|<quasi|<xmacro|x|<with|<unquote*|<quote-arg|w>>|<quote|<quasi|<compound|<unquote*|<quote-arg|x>>>>>>>>>>

otherwise the idea works as this hard-wired version shows:
<assign|enclose|<xmacro|w|<quasi|<xmacro|x|<with|<unquote*|<quote-arg|w>>|Hello <value|a> there>>>>>

That hard wired version fixes the body, and can be executed with:
<assign|tc|<enclose|a|HEE HEE>>
<tc>

I tried deferring the body execution into an xcompound macro, like this:
<assign|xcompound|<xmacro|x|<quasi|<compound|<unquote*|<quote-arg|x>>>>>>

<assign|enclose|<xmacro|w|<quasi|<xmacro|x|<with|<unquote*|<quote-arg|w>>|<xcompound|<arg|x>>>>>>>

But then texmacs just segfaults. I guess to call xcompound still needs to be using quasi unquote* quote-arg

Can anyone help me preserve SECOND quasi and unquote* in the emitted macro while still allowing the FIRST unquote* in the with block to be expanded?

Sam

reply via email to

[Prev in Thread] Current Thread [Next in Thread]