ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Expansion help needed, getvariable and TABLE
@ 2018-01-31  2:10 Rik Kabel
  2018-01-31  2:31 ` Rik Kabel
  2018-01-31  6:04 ` Wolfgang Schuster
  0 siblings, 2 replies; 7+ messages in thread
From: Rik Kabel @ 2018-01-31  2:10 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 2841 bytes --]

Listers,

I have a problem, and a question on ConTeXt programming efficiency.

In the example below, I have a set of variables. When these are 
reference directly via \getvariable, everything works as expected in 
simple text and in TABLEs. When I \define a macro to the \getvariable, 
that works in simple text, but only the value of the last iteration 
appears in the TABLE. The macro definition is saved and when it is used, 
that is the value that it has.

So, how can I \define (or \def, ...) a macro to the expanded value to 
avoid this? That is the problem.

The question is, Is there is any advantage to be had in doing this? 
Assume that the value is referenced many (tens of) times. There seems to 
be an aesthetic value of factoring out the multiple identical instances 
of the \getvariable syntax and assigning a more semantically informative 
name, but beyond that, is there any other value?

    % macros=mkvi engine=luajittex

    \setvariables      [one]
                        [a=1a,b=1b]
    \setvariables      [two]
                        [a=2a,b=2b]

    \define            \Sets
                        {one,two}

    \starttexdefinition unexpanded doInlineText #SET
         Direct: \getvariable{#SET}{a} \getvariable{#SET}{b}\par
    \stoptexdefinition

    \starttexdefinition unexpanded doTableRow #SET
         \bTR
           \bTC\getvariable{#SET}{a}\eTC
           \bTC\getvariable{#SET}{b}\eTC
         \eTR
    \stoptexdefinition

    \starttexdefinition doInlineTextExp #SET
         \define\A{\getvariable{#SET}{a}}
         \define\B{\getvariable{#SET}{b}}
         Factored: \A\ \B\par
    \stoptexdefinition

    \starttexdefinition doTableRowExp #SET
         \define\A{\getvariable{#SET}{a}}
         \define\B{\getvariable{#SET}{b}}
         \bTR
           \bTC\A\eTC
           \bTC\B\eTC
         \eTR
    \stoptexdefinition

    \starttext

    \starttext

    \expandafter\processcommalist\expandafter[\Sets]\doInlineText

         \bTABLE[frame=off]
           \bTABLEhead
             \bTR[nc=2]
               \bTH Direct\eTH
             \eTR
           \eTABLEhead
           \bTABLEbody
    \expandafter\processcommalist\expandafter[\Sets]\doTableRow
           \eTABLEbody
         \eTABLE

    \expandafter\processcommalist\expandafter[\Sets]\doInlineTextExp

         \bTABLE[frame=off]
           \bTABLEhead
             \bTR[nc=2]
               \bTH Factored\eTH
             \eTR
           \eTABLEhead
           \bTABLEbody
    \expandafter\processcommalist\expandafter[\Sets]\doTableRowExp
           \eTABLEbody
         \eTABLE

    \stoptext

-- 
Rik


[-- Attachment #1.2: Type: text/html, Size: 3815 bytes --]

[-- Attachment #2: Type: text/plain, Size: 492 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-01-31 16:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-31  2:10 Expansion help needed, getvariable and TABLE Rik Kabel
2018-01-31  2:31 ` Rik Kabel
2018-01-31  6:04 ` Wolfgang Schuster
2018-01-31 14:47   ` Rik Kabel
2018-01-31 14:54     ` Wolfgang Schuster
2018-01-31 15:40       ` Rik Kabel
2018-01-31 16:06         ` Hans Hagen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).