texmacs-dev
[Top][All Lists]
Advanced

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

Re: [Texmacs-dev] Manual closures


From: Sam Liddicott
Subject: Re: [Texmacs-dev] Manual closures
Date: Thu, 24 May 2012 13:37:33 +0100

This seems to do the trick in a different way:

<assign|enclose|<xmacro|w|<quasiquote|<xmacro|x|<with|<unquote*|<quote-arg|w>>|<map-args|identity|eval|x>>>>>>

Which really means only the first argument is any use... but it could be a concat which contains other macro calls...

This attempt to preserve the old (less useful?) intention:
<assign|enclose|<xmacro|w|<quasiquote|<xmacro|x|<with|<unquote*|<quote-arg|w>>|<map-args|identity|<arg|x|0>|x|1>>>>>>

just emits: <error|invalid map arguments>
when called with: <tc|merge|a|b|c>

but I don't see why.

Anyway, so my closure-making enclose macro is:
<assign|enclose|<xmacro|w|<quasiquote|<macro|x|<with|<unquote*|<quote-arg|w>>|<arg|x>>>>>>

Next question. Why does texmacs segfault when trying to get the number of arguments to an xmacro. length when applied to the argument segfaults?
<length|<quote-arg|w>> returns error-bad length

This works: <length|<tuple|<unquote*|<quote-arg|w>>>> (to my surprise without the need for quasi, so I learned something there - quasi just makes it happen earlier)

EVEN MORE interesting: <get-label|<quote-arg|w>> will return the NAME of the macro being executed! How's that for sneakiness! Oh yes!


On Thu, May 24, 2012 at 8:37 AM, Sam Liddicott <address@hidden> wrote:
I tried some unquote quote as an attempt preserve something past the first quasi. The unquote should cause the quote to be evaluated which removes the quote and leaves things as they were

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

Using compound (above) I got a segfault, using eval (below) instead (which seemed to work when substituted in the simpler incomplete) cases emits: bad eval bridge
<assign|enclose|<xmacro|w|<quasi|<xmacro|x|<quasi|<with|<unquote*|<quote-arg|w>>|<unquote|<quote|<eval|<unquote*|<quote-arg|x>>>>>>>>>>>



On Thu, May 24, 2012 at 8:25 AM, Sam Liddicott <address@hidden> wrote:
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]