mailing-list for TeXmacs Users

Text archives Help


Re: [TeXmacs] how can I write infix operators with arbitrary many args with xmacros


Chronological Thread 
  • From: Joris van der Hoeven <address@hidden>
  • To: address@hidden
  • Subject: Re: [TeXmacs] how can I write infix operators with arbitrary many args with xmacros
  • Date: Fri, 2 Feb 2007 10:06:18 +0100

On Fri, Feb 02, 2007 at 09:55:55AM +0100, Immanuel Normann wrote:
> I would like to have a convenient generic macro (or xmacro) that takes one
> argument representig an infix operator and arbitrary many successive
> arguments representing the operands of tht operator; e.g.:
>
> <generic-infix-macro|+|4|2|5> should expand to "4+2+5"
>
> I know the TeXmacs help page on "Macro primitives" where a very similiar
> example of application is given:
>
> <assign|comma-extra|<macro|x|, <arg|x>>>
>
> <assign|comma-separated|
> <xmacro|args|
> <concat<arg|args|0>
> <map-args|comma-extra|concat|args|1>>>>>
>
> Where <comma-separate|a|b|c> expands to "a,b,c"
>
> However this example unfortunately does not solve my problem, since you
> can't pass "comma-separated" the "comma" as argument (representing the
> infix operator in this case).
> And it is very awkward to write always two macros in the pattern of
> "comma-extra" and "comma-separated" for every infix operator. And one
> needs infix operators with arbitrary operands quite often.

If the purpose of your question is to write macros for semantic markup,
then you will also have a problem with putting additional parentheses
or not. In that case, I suggest rather to use the "extern" primitive,
which allows you to use an arbitrary scheme function for rewriting purposes.

If you want to stick to the macro language, you might store the "+"
in an environment variable "current-infix-operator" using with and
then do something analoguous to "comma-separated".

Best wishes, Joris



Archive powered by MHonArc 2.6.19.

Top of page