From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/76768 Path: news.gmane.org!not-for-mail From: Philipp Gesang Newsgroups: gmane.comp.tex.context Subject: Re: expansion and \processaction Date: Thu, 7 Jun 2012 17:34:38 +0200 Message-ID: <20120607153438.GB4444@phlegethon> References: <20120607120526.GA4444@phlegethon> <512FF611-2B42-42FA-8539-8D3F8585E687@googlemail.com> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1816798468==" X-Trace: dough.gmane.org 1339083211 29477 80.91.229.3 (7 Jun 2012 15:33:31 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 7 Jun 2012 15:33:31 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Thu Jun 07 17:33:29 2012 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from balder.ntg.nl ([195.12.62.10]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SceiB-0007TE-PI for gctc-ntg-context-518@m.gmane.org; Thu, 07 Jun 2012 17:33:23 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 2F51C101E3; Thu, 7 Jun 2012 17:33:23 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (localhost [127.0.0.1]) (amavisd-new, port 10024) with LMTP id zhu26kEJsmdG; Thu, 7 Jun 2012 17:33:21 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 5834E101E0; Thu, 7 Jun 2012 17:33:21 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id A725A101E0 for ; Thu, 7 Jun 2012 17:33:20 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (localhost [127.0.0.1]) (amavisd-new, port 10024) with LMTP id i3ZPVPlv9fVX for ; Thu, 7 Jun 2012 17:33:19 +0200 (CEST) Original-Received: from filter3-ams.mf.surf.net (filter3-ams.mf.surf.net [192.87.102.71]) by balder.ntg.nl (Postfix) with ESMTP id 1A6BF101DD for ; Thu, 7 Jun 2012 17:33:18 +0200 (CEST) Original-Received: from relay2.uni-heidelberg.de (relay2.uni-heidelberg.de [129.206.210.211]) by filter3-ams.mf.surf.net (8.14.3/8.14.3/Debian-9.4) with ESMTP id q57FX3bb015707 for ; Thu, 7 Jun 2012 17:33:09 +0200 Original-Received: from ix.urz.uni-heidelberg.de (cyrus-portal.urz.uni-heidelberg.de [129.206.100.176]) by relay2.uni-heidelberg.de (8.13.8/8.13.8) with ESMTP id q57FX10E032133 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 7 Jun 2012 17:33:01 +0200 Original-Received: from extmail.urz.uni-heidelberg.de (extmail.urz.uni-heidelberg.de [129.206.100.140]) by ix.urz.uni-heidelberg.de (8.13.8/8.13.8) with ESMTP id q57FX0gL013785 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 7 Jun 2012 17:33:00 +0200 Original-Received: from localhost (dslb-188-104-150-055.pools.arcor-ip.net [188.104.150.55]) (authenticated bits=0) by extmail.urz.uni-heidelberg.de (8.13.4/8.13.1) with ESMTP id q57FWxdc007531 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Thu, 7 Jun 2012 17:33:00 +0200 Mail-Followup-To: mailing list for ConTeXt users In-Reply-To: <512FF611-2B42-42FA-8539-8D3F8585E687@googlemail.com> X-Operating-System: Linux phlegethon 3.3.7-1-ARCH X-License: "CC-BY-SA 3.0" User-Agent: Mutt/1.5.21 (2010-09-15) X-Bayes-Prob: 0.0001 (Score 0, tokens from: @@RPTN) X-CanIt-Geo: ip=129.206.210.211; country=DE; region=01; city=Heidelberg; latitude=49.4167; longitude=8.7000; http://maps.google.com/maps?q=49.4167,8.7000&z=6 X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 03Hjrx3IU - 0416d7eeb347 - 20120607 (trained as not-spam) X-Scanned-By: CanIt (www . roaringpenguin . com) on 192.87.102.71 X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.13 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: ntg-context-bounces@ntg.nl Errors-To: ntg-context-bounces@ntg.nl Xref: news.gmane.org gmane.comp.tex.context:76768 Archived-At: --===============1816798468== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="CdrF4e02JqNVZeln" Content-Disposition: inline --CdrF4e02JqNVZeln Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi Wolfgang! =C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7 >=20 > Am 07.06.2012 um 14:05 schrieb Philipp Gesang: >=20 > > Hi all, > >=20 > > my goal is a macro \definestates[foo][...,...] which takes a comma > > list and creates a monadic macro \foo[n]. \foo[n] should return > > either the nth item or, if (n > list length), a default. I > > thought the right tools were \processcommalist to generate the > > mapping n->, as well as \processaction to retrieve the > > items. But naively I didn=E2=80=99t consider expansion ... > >=20 > > My code so far: > >=20 > > =C2=B7=C2=B78<=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2= =B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7= =C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2= =B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7= =C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2= =B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7 > > \unprotect > >=20 > > \def\definestates{\dodoubleempty\do_define_states} > >=20 > > \def\do_define_states[#1][#2]{% > > \expandafter\edef\csname#1_states\endcsname{% > > \nstates0 > > %% this is supposed to be expanded so we employ the \raw... variety > > \rawprocesscommalist[#2]\add_one_state% > > unknown=3D>\dummystate,% > > default=3D>\dummystate,% > > }% > > \do_do_define_states{#1}% > > } > >=20 > > \let\dummystate\empty > >=20 > > \newcount\nstates > > \unexpanded\def\add_one_state#1{% > > \advance\nstates\plusone > > \the\nstates=3D>#1,% > > } > >=20 > > \def\do_do_define_states#1{% > > \expandafter\def\csname#1\endcsname > > {\expandafter\dosingleempty\csname do_#1\endcsname}% > > \expandafter\def\csname do_#1\endcsname[##1]{% > > \iffirstargument > > % <[DBG] cmd:#1, state:##1>\par > > \edef\currentstates{\csname#1_states\endcsname}% > > %% At this point \currentstates should yield the whole mapping so > > %% we can use it with \processaction. But ... > > % \show\currentstates > > % \currentstates\par > > %% ... here it still contains > > %% \nstates 0 \rawprocesscommalist [foo,bar,baz] ... > > %% and the next directive has an empty result: > > \rawprocessaction[##1][\currentstates]% > > \fi > > }% > > } > >=20 > > \protect > > \starttext > >=20 > > \definestates[mystates][foo,bar,baz] > > %% At this point I=E2=80=99d like \mystates_states to contain (literall= y) > > %% =E2=80=9C1=3D>foo,2=3D>bar,3=3D>baz,unknown=3D>,default=3D>,=E2=80= =9D > > %% so the following command > > \mystates[1] % -> foo > > %% would be equivalent to > > %% \processaction[1][1=3D>foo,2=3D>bar,3=3D>baz,unknown=3D>,default= =3D>,] > > \mystates[2] % -> bar > > \mystates[42] % -> dummy > >=20 > > \stoptext > > =C2=B7=C2=B78<=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2= =B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7= =C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2= =B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7= =C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2= =B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7 > >=20 > > My question: How can I use \[raw]processcommalist in an expanded > > definition? How can I get \[raw]processcommalist to operate on > > the expansion of its second argument? Does this even make sense? > > If not, what is the proper way? >=20 > \unprotect >=20 > \unexpanded\def\definestates > {\dodoubleargument\definestates_indeed} >=20 > \def\definestates_indeed[#1][#2]% > {\setuevalue{#1}{\states_entry[#2]}} >=20 > \unexpanded\def\states_entry > {\dodoubleargument\states_entry_indeed} >=20 > \def\states_entry_indeed[#1][#2]% > {\getcommalistsize[#1]% > \ifnum#2>\commalistsize > {\tttf NO ENTRY!}% > \else > \getfromcommalist[#1][#2]\commalistelement > \fi} Thanks very much. This solves my problem. Very convenient that I can rewrite it to use commacommand. Philipp >=20 > \protect >=20 > \starttext >=20 > \definestates[mystates][foo,bar,baz] >=20 > \starttabulate > \NC 2 \EQ \mystates [2] \NC\NR > \NC 42 \EQ \mystates[42] \NC\NR > \stoptabulate >=20 > \stoptext >=20 > Wolfgang > _________________________________________________________________________= __________ > If your question is of interest to others as well, please add an entry to= the Wiki! >=20 > maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-co= ntext > webpage : http://www.pragma-ade.nl / http://tex.aanhet.net > archive : http://foundry.supelec.fr/projects/contextrev/ > wiki : http://contextgarden.net > _________________________________________________________________________= __________ --=20 () ascii ribbon campaign - against html e-mail /\ www.asciiribbon.org - against proprietary attachments --CdrF4e02JqNVZeln Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) iEYEARECAAYFAk/Qyg4ACgkQ02lYlJYWs9IumQCbBrTfY0TwPcQtCW8m3jz6buCG KG0An3QrtnivFdb4hB18CrF5RY6fPOQR =ypaN -----END PGP SIGNATURE----- --CdrF4e02JqNVZeln-- --===============1816798468== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ___________________________________________________________________________________ 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://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________ --===============1816798468==--