* Re: serial definition
@ 2006-01-03 14:11 Henning Hraban Ramm
2006-01-06 21:25 ` Willi Egger
0 siblings, 1 reply; 8+ messages in thread
From: Henning Hraban Ramm @ 2006-01-03 14:11 UTC (permalink / raw)
(This mail was rejected as spam in my first try, and the reject
message was catched by my spam filter...)
Am 2006-01-03 um 11:51 schrieb Taco Hoekwater:
> You need to expand the \Set commands in that first loop,
> otherwise you store the literal token \recursevelel inside
> the definitions of the Key and Val macros (\setvalue{}{}
> autoexpands its first argument, but not its second argument).
>
> When not inside a recursion, \recurselevel expands to the number
> 0 (zero) in the "manual bit", and you are actually re-evaluating
> the macro using the then current \recurselevel definition
> when inside the "looping" bit.
The magic expansion hit me again, I should've known it.
> So you need:
>
> \dostepwiserecurse{1}{9}{1}{
> \expanded{\Set{\recurselevel}{K\recurselevel}{V\recurselevel}}
> }
>
> I hope this is clear enough?
Thank you very much!
Actually, in the real environment I needed the \expanded at another
place:
\def\Sender#1#2#3{\setvalue{SenderKey#1}{#2}\setvalue{SenderVal#1}{#3}}
\def\GetSenderLine#1{\bTR\bTD\doiftextelse{\getvalue{SenderKey#1}}
{\getvalue{SenderKey#1}:}{}\eTD\bTD\getvalue{SenderVal#1}\eTD\eTR}
% initialize values (not even needed)
\dostepwiserecurse{1}{9}{1}{
\Sender{\recurselevel}{}{}
}
\startsetups sendertablesetup
\setupTABLE[frame=off]
\setupTABLE[x][1][width=\senderkeywidth, align=left, style={\keystyle
\strut}]
\setupTABLE[x][2][width=\sendervalwidth, align=right, style=
{\valstyle\strut}]
\bTABLE
\dostepwiserecurse{1}{9}{1}{% count from 1 to 9, step 1
\expanded{\GetSenderLine{\recurselevel}}
}
\eTABLE
\stopsetups
I collect this (and more) at http://wiki.contextgarden.net/
Talk:Letter_style
Grüßlis vom Hraban!
---
http://www.fiee.net/texnique/
http://contextgarden.net
http://www.cacert.org (I'm an assurer)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: serial definition
2006-01-03 14:11 serial definition Henning Hraban Ramm
@ 2006-01-06 21:25 ` Willi Egger
0 siblings, 0 replies; 8+ messages in thread
From: Willi Egger @ 2006-01-06 21:25 UTC (permalink / raw)
[-- Attachment #1: Type: text/plain, Size: 2664 bytes --]
Hi Hraban, Hans, Taco,
I followed this thread with interest. By coincidence I was struggling
with this kind of problem during the last days. Thanks so much for this
educative example!
In my case I have to fill in a table with the information concerning
parcels to be sent. Some times there is a single one sometimes there are
multiple pieces. For each of the parcels I have to fill in a table-row.
And voilà! The community cooked up the pieces I missed. Thanks again.
Willi
Henning Hraban Ramm wrote:
> (This mail was rejected as spam in my first try, and the reject
> message was catched by my spam filter...)
>
> Am 2006-01-03 um 11:51 schrieb Taco Hoekwater:
>
>> You need to expand the \Set commands in that first loop,
>> otherwise you store the literal token \recursevelel inside
>> the definitions of the Key and Val macros (\setvalue{}{}
>> autoexpands its first argument, but not its second argument).
>>
>> When not inside a recursion, \recurselevel expands to the number
>> 0 (zero) in the "manual bit", and you are actually re-evaluating
>> the macro using the then current \recurselevel definition
>> when inside the "looping" bit.
>
>
> The magic expansion hit me again, I should've known it.
>
>> So you need:
>>
>> \dostepwiserecurse{1}{9}{1}{
>> \expanded{\Set{\recurselevel}{K\recurselevel}{V\recurselevel}}
>> }
>>
>> I hope this is clear enough?
>
>
> Thank you very much!
> Actually, in the real environment I needed the \expanded at another
> place:
>
> \def\Sender#1#2#3{\setvalue{SenderKey#1}{#2}\setvalue{SenderVal#1}{#3}}
> \def\GetSenderLine#1{\bTR\bTD\doiftextelse{\getvalue{SenderKey#1}}
> {\getvalue{SenderKey#1}:}{}\eTD\bTD\getvalue{SenderVal#1}\eTD\eTR}
> % initialize values (not even needed)
> \dostepwiserecurse{1}{9}{1}{
> \Sender{\recurselevel}{}{}
> }
>
> \startsetups sendertablesetup
> \setupTABLE[frame=off]
> \setupTABLE[x][1][width=\senderkeywidth, align=left,
> style={\keystyle \strut}]
> \setupTABLE[x][2][width=\sendervalwidth, align=right, style=
> {\valstyle\strut}]
> \bTABLE
> \dostepwiserecurse{1}{9}{1}{% count from 1 to 9, step 1
> \expanded{\GetSenderLine{\recurselevel}}
> }
> \eTABLE
> \stopsetups
>
> I collect this (and more) at http://wiki.contextgarden.net/
> Talk:Letter_style
>
>
>
> Grüßlis vom Hraban!
> ---
> http://www.fiee.net/texnique/
> http://contextgarden.net
> http://www.cacert.org (I'm an assurer)
>
> _______________________________________________
> ntg-context mailing list
> ntg-context@ntg.nl
> http://www.ntg.nl/mailman/listinfo/ntg-context
[-- Attachment #2: infotable.tex --]
[-- Type: text/plain, Size: 2114 bytes --]
% Info-sheet for the parcel service
% Context file
% filename: infotable.tex
% W.Egger
% 06-01-2006
% Thanks to a thread on the Context mailinglist this works now!
\environment layout
\setupbodyfont[10pt]
\setuppapersize[A4,landscape][A4,landscape]
\setuplayout[
topspace=1.5cm,
backspace=1.5cm,
width=27cm]
\setupheadertexts[\leftaligned{\bfd Parcel service info-sheet}]
\def\Addressee#1#2#3#4#5#6#7#8{%
\setvalue{Ordno#1}{#2}%
\setvalue{Bestno#1}{#3}%
\setvalue{Adres#1}{#4}%
\setvalue{Dimension#1}{#5}%
\setvalue{Weight#1}{#6}%
\setvalue{Value#1}{#7}%
\setvalue{Tel#1}{#8}}
\def\Parcel#1{%
\bTR%
\bTD\getvalue{Ordno#1}%
\doiftextelse{\getvalue{Bestno#1}}%
{\blank[small]Ext. Orderno:\par\hfill\getvalue{Bestno#1}}{\strut\blank} \eTD%
\bTD \getvalue{Adres#1} \eTD%
\bTD \getvalue{Dimension#1} \eTD%
\bTD \getvalue{Weight#1} \eTD%
\bTD \getvalue{Value#1} \eTD%
\bTD \getvalue{Tel#1} \eTD\eTR}
\def\Numberofparcels{3}
\starttext
\Addressee{1}%
{293-291}%Ordernumber
{12345-2009}%External ordernumber
{Maximilian Smallbody\\ Sunshinestreet 24\\ 3456 EE Natland\\ Cloudyland}%Addres
{70 x 67 x 15 cm}%Dimension
{7.5 kg}%Weight
{1.000.00\euro}%Value
{+31 455535251}%Phone
\Addressee{2}%
{293-292}%TC-nummer
{}%External ordernumber
{Milly Milltower\\ 3\high{rd} Duststreet\\ Millerstown 56789\\ Millersland}%Addres
{120 x 12 x 12 cm}%Dimension
{2.5 kg}%Gewicht
{293.00\euro}%Waarde buiten EU
{+99-9192939495}%Telefoon
\Addressee{3}%
{}%
{}%
{}%
{}%
{}%
{}%
{}%
%= Do not edit below this line!=
{\bfa Date: \date}
\blank[1.5cm]
\bTABLE
\setupTABLE[row][first][style=bold,align=middle]
\setupTABLE[column][each][width=.166\textwidth,align=right]
\setupTABLE[x][3][align=middle]
\setupTABLE[x][4][align=left]
\setupTABLE[x][5][align=left]
\bTR
\bTD Ordernumber\eTD
\bTD Address \eTD
\bTD Dimension \eTD
\bTD Weight \eTD
\bTD Value \eTD
\bTD Phone \eTD\eTR
\dostepwiserecurse{1}{\Numberofparcels}{1}{%
\expanded{\Parcel{\recurselevel}}}
\eTABLE
\stoptext
[-- Attachment #3: Type: text/plain, Size: 139 bytes --]
_______________________________________________
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: serial definition
2006-01-03 10:51 ` Taco Hoekwater
@ 2006-01-03 17:22 ` Hans Hagen
0 siblings, 0 replies; 8+ messages in thread
From: Hans Hagen @ 2006-01-03 17:22 UTC (permalink / raw)
Taco Hoekwater wrote:
>
>
> Peter Rolf wrote:
>
>>>
>>> Why do I get K0/V0 for \Get{3}? - it works with \recurselevel!
>>>
>
> You need to expand the \Set commands in that first loop,
> otherwise you store the literal token \recursevelel inside
> the definitions of the Key and Val macros (\setvalue{}{}
> autoexpands its first argument, but not its second argument).
>
> When not inside a recursion, \recurselevel expands to the number
> 0 (zero) in the "manual bit", and you are actually re-evaluating
> the macro using the then current \recurselevel definition
> when inside the "looping" bit.
>
> So you need:
>
> \dostepwiserecurse{1}{9}{1}{
> \expanded{\Set{\recurselevel}{K\recurselevel}{V\recurselevel}}
> }
>
> I hope this is clear enough?
even this works (#1 being the expanded \recurselevel):
\dostepwiserecurse{1}{9}{1}{
\setvalue{hi there #1}{#1 indeed}
}
\getvalue{hi there 4}
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: serial definition
2006-01-03 10:33 ` Peter Rolf
@ 2006-01-03 10:51 ` Taco Hoekwater
2006-01-03 17:22 ` Hans Hagen
0 siblings, 1 reply; 8+ messages in thread
From: Taco Hoekwater @ 2006-01-03 10:51 UTC (permalink / raw)
Peter Rolf wrote:
>>
>>Why do I get K0/V0 for \Get{3}? - it works with \recurselevel!
>>
You need to expand the \Set commands in that first loop,
otherwise you store the literal token \recursevelel inside
the definitions of the Key and Val macros (\setvalue{}{}
autoexpands its first argument, but not its second argument).
When not inside a recursion, \recurselevel expands to the number
0 (zero) in the "manual bit", and you are actually re-evaluating
the macro using the then current \recurselevel definition
when inside the "looping" bit.
So you need:
\dostepwiserecurse{1}{9}{1}{
\expanded{\Set{\recurselevel}{K\recurselevel}{V\recurselevel}}
}
I hope this is clear enough?
Cheers, Taco
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: serial definition
2006-01-02 21:46 ` Henning Hraban Ramm
@ 2006-01-03 10:33 ` Peter Rolf
2006-01-03 10:51 ` Taco Hoekwater
0 siblings, 1 reply; 8+ messages in thread
From: Peter Rolf @ 2006-01-03 10:33 UTC (permalink / raw)
Henning Hraban Ramm wrote:
...
> After some hacking I learned how \setvalue works:
>
> <TEX>
> \def\Set#1#2#3{\setvalue{Key#1}{#2}\setvalue{Val#1}{#3}}
> \def\Get#1{\getvalue{Key#1}/\getvalue{Val#1}}
>
> \dostepwiserecurse{1}{9}{1}{
> \Set{\recurselevel}{K\recurselevel}{V\recurselevel}
> }
> \Set{1}{eins}{EINS}
> \Set{2}{zwei}{ZWEI}
>
> manually: \Get{1} -- \Get{2} -- \Get{3}
>
> looping:
> \dostepwiserecurse{1}{5}{1}{
> \Get{\recurselevel} --
> }
> </TEX>
>
> results in:
>
> manually: eins/EINS – zwei/ZWEI – K0/V0
> looping: eins/EINS – zwei/ZWEI – K3/V3 – K4/V4 – K5/V5 –
>
> Why do I get K0/V0 for \Get{3}? - it works with \recurselevel!
>
Is this the TeX riddle of the week? Where is the camera? ;)
Sorry, I have no clue, so you better ask the wizzards...
Greetings, Peter
>
> Grüßlis vom Hraban!
> ---
> http://www.fiee.net/texnique/
> http://contextgarden.net
> http://www.cacert.org (I'm an assurer)
>
> _______________________________________________
> ntg-context mailing list
> ntg-context@ntg.nl
> http://www.ntg.nl/mailman/listinfo/ntg-context
>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: serial definition
2006-01-02 18:20 ` Peter Rolf
@ 2006-01-02 21:46 ` Henning Hraban Ramm
2006-01-03 10:33 ` Peter Rolf
0 siblings, 1 reply; 8+ messages in thread
From: Henning Hraban Ramm @ 2006-01-02 21:46 UTC (permalink / raw)
Am 2006-01-02 um 19:20 schrieb Peter Rolf:
> You can use \newcounter for such stuff or the context recurse
> functions
> (with \recurselevel).
I tried the following:
<TEX>
\dostepwiserecurse{1}{9}{1}{% count from 1 to 9, step 1
\def\lettersenderkey\recurselevel{}
\def\lettersenderval\recurselevel{}
\def\Sender\recurselevel#1#2{%
\def\lettersenderkey\recurselevel{#1}%
\def\lettersenderval\recurselevel{#2}}
}
\Sender1{Name}{Hraban}
</TEX>
--> ! Use of Sender doesn't match its definition.
Seems like \def\Something\recurselevel isn't valid.
(Sure, just confirmed in the TeXbook, numbers aren't considered
command-word characters.)
After some hacking I learned how \setvalue works:
<TEX>
\def\Set#1#2#3{\setvalue{Key#1}{#2}\setvalue{Val#1}{#3}}
\def\Get#1{\getvalue{Key#1}/\getvalue{Val#1}}
\dostepwiserecurse{1}{9}{1}{
\Set{\recurselevel}{K\recurselevel}{V\recurselevel}
}
\Set{1}{eins}{EINS}
\Set{2}{zwei}{ZWEI}
manually: \Get{1} -- \Get{2} -- \Get{3}
looping:
\dostepwiserecurse{1}{5}{1}{
\Get{\recurselevel} --
}
</TEX>
results in:
manually: eins/EINS – zwei/ZWEI – K0/V0
looping: eins/EINS – zwei/ZWEI – K3/V3 – K4/V4 – K5/V5 –
Why do I get K0/V0 for \Get{3}? - it works with \recurselevel!
Grüßlis vom Hraban!
---
http://www.fiee.net/texnique/
http://contextgarden.net
http://www.cacert.org (I'm an assurer)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: serial definition
2006-01-02 14:54 Henning Hraban Ramm
@ 2006-01-02 18:20 ` Peter Rolf
2006-01-02 21:46 ` Henning Hraban Ramm
0 siblings, 1 reply; 8+ messages in thread
From: Peter Rolf @ 2006-01-02 18:20 UTC (permalink / raw)
Hi ho Hraban,
Henning Hraban Ramm wrote:
> Hi ho!
>
> This is a part of Holger Schöner's letter style (see
> http://wiki.contextgarden.net/Letter_style):
>
> \def\lettersenderkeyone{}
> \def\lettersendervalone{}
> \def\lettersenderkeytwo{}
> \def\lettersendervaltwo{}
> % etc.
> \def\lettersenderkeynine{}
> \def\lettersendervalnine{}
>
> \def\senderone#1#2{\def\lettersenderkeyone{#1}\def\lettersendervalone{#2}}
> \def\sendertwo#1#2{\def\lettersenderkeytwo{#1}\def\lettersendervaltwo{#2}}
> % etc.
> \def\sendernine#1#2{\def\lettersenderkeynine{#1}\def\lettersendervalnine{#2}}
>
>
> \startsetups sendertablesetup
> \bTABLE
> \setupTABLE[frame=off]
> \setupTABLE[x][1][width=\senderkeywidth, align=left,
> style={\keystyle\strut}]
> \setupTABLE[x][2][width=\sendervalwidth, align=right,
> style={\valstyle\strut}]
> \bTR\bTD\doiftextelse{\lettersenderkeyone}
> {\lettersenderkeyone:}{}\eTD\bTD\lettersendervalone\eTD\eTR
> \bTR\bTD\doiftextelse{\lettersenderkeytwo}
> {\lettersenderkeytwo:}{}\eTD\bTD\lettersendervaltwo\eTD\eTR
> % etc.
> \bTR\bTD\doiftextelse{\lettersenderkeynine}
> {\lettersenderkeynine:}{}\eTD\bTD\lettersendervalnine \eTD\eTR
> \eTABLE
> \stopsetups
>
> Is there a more programmatical way for such? (Does TeX know something
> like arrays or dicts?)
> Sorry, I still can't program in TeX...
>
Welcome to the club ;)
You can use \newcounter for such stuff or the context recurse functions
(with \recurselevel).
\starttext
\dostepwiserecurse{1}{9}{1}{% count from 1 to 9, step 1
\setvalue{PREFIX\recurselevel}{\recurselevel}
}
% or all by hand (not useful for simple loops)
\newcounter\Row % Row=0
\increment\Row % Row+=1
\doloop{%
\setvariables[PREFIX\Row][foo=foo\Row]
\increment\Row
\ifnum\Row>9 \exitloop\fi
}
% reset to one by hand
\newcounter\Row
\increment\Row
\dostepwiserecurse{1}{9}{1}{%
\getvariable{PREFIX\Row}{foo}=
\getvalue{PREFIX\recurselevel}\crlf
\increment\Row
}
\stoptext
You can combine x counters to simulate a x-dimensional array (but you
better wait for lua). Hope that helps.
Greetings, Peter
>
> Grüßlis vom Hraban!
> ---
> http://www.fiee.net/texnique/
> http://contextgarden.net
> http://www.cacert.org (I'm an assurer)
>
> _______________________________________________
> ntg-context mailing list
> ntg-context@ntg.nl
> http://www.ntg.nl/mailman/listinfo/ntg-context
>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* serial definition
@ 2006-01-02 14:54 Henning Hraban Ramm
2006-01-02 18:20 ` Peter Rolf
0 siblings, 1 reply; 8+ messages in thread
From: Henning Hraban Ramm @ 2006-01-02 14:54 UTC (permalink / raw)
Hi ho!
This is a part of Holger Schöner's letter style (see http://
wiki.contextgarden.net/Letter_style):
\def\lettersenderkeyone{}
\def\lettersendervalone{}
\def\lettersenderkeytwo{}
\def\lettersendervaltwo{}
% etc.
\def\lettersenderkeynine{}
\def\lettersendervalnine{}
\def\senderone#1#2{\def\lettersenderkeyone{#1}\def\lettersendervalone
{#2}}
\def\sendertwo#1#2{\def\lettersenderkeytwo{#1}\def\lettersendervaltwo
{#2}}
% etc.
\def\sendernine#1#2{\def\lettersenderkeynine{#1}\def
\lettersendervalnine{#2}}
\startsetups sendertablesetup
\bTABLE
\setupTABLE[frame=off]
\setupTABLE[x][1][width=\senderkeywidth, align=left, style=
{\keystyle\strut}]
\setupTABLE[x][2][width=\sendervalwidth, align=right, style=
{\valstyle\strut}]
\bTR\bTD\doiftextelse{\lettersenderkeyone}
{\lettersenderkeyone:}{}\eTD\bTD\lettersendervalone\eTD\eTR
\bTR\bTD\doiftextelse{\lettersenderkeytwo}
{\lettersenderkeytwo:}{}\eTD\bTD\lettersendervaltwo\eTD\eTR
% etc.
\bTR\bTD\doiftextelse{\lettersenderkeynine}
{\lettersenderkeynine:}{}\eTD\bTD\lettersendervalnine \eTD\eTR
\eTABLE
\stopsetups
Is there a more programmatical way for such? (Does TeX know something
like arrays or dicts?)
Sorry, I still can't program in TeX...
Grüßlis vom Hraban!
---
http://www.fiee.net/texnique/
http://contextgarden.net
http://www.cacert.org (I'm an assurer)
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2006-01-06 21:25 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-03 14:11 serial definition Henning Hraban Ramm
2006-01-06 21:25 ` Willi Egger
-- strict thread matches above, loose matches on Subject: below --
2006-01-02 14:54 Henning Hraban Ramm
2006-01-02 18:20 ` Peter Rolf
2006-01-02 21:46 ` Henning Hraban Ramm
2006-01-03 10:33 ` Peter Rolf
2006-01-03 10:51 ` Taco Hoekwater
2006-01-03 17:22 ` 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).