From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/76759 Path: news.gmane.org!not-for-mail From: Philipp Gesang Newsgroups: gmane.comp.tex.context Subject: expansion and \processaction Date: Thu, 7 Jun 2012 14:05:26 +0200 Message-ID: <20120607120526.GA4444@phlegethon> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0374874095==" X-Trace: dough.gmane.org 1339070645 14029 80.91.229.3 (7 Jun 2012 12:04:05 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 7 Jun 2012 12:04:05 +0000 (UTC) To: ConTeXt ML Original-X-From: ntg-context-bounces@ntg.nl Thu Jun 07 14:04:03 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 1ScbRV-00042N-A0 for gctc-ntg-context-518@m.gmane.org; Thu, 07 Jun 2012 14:03:57 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id C9A04101E6; Thu, 7 Jun 2012 14:03:56 +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 ShbHeVgjvspp; Thu, 7 Jun 2012 14:03:54 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id E7EA2101E0; Thu, 7 Jun 2012 14:03:53 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id DCC41101E0 for ; Thu, 7 Jun 2012 14:03:52 +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 uz7Yp42P-dRM for ; Thu, 7 Jun 2012 14:03:51 +0200 (CEST) Original-Received: from filter1-til.mf.surf.net (filter1-til.mf.surf.net [194.171.167.217]) by balder.ntg.nl (Postfix) with ESMTP id E416E101DD for ; Thu, 7 Jun 2012 14:03:51 +0200 (CEST) Original-Received: from relay2.uni-heidelberg.de (relay2.uni-heidelberg.de [129.206.210.211]) by filter1-til.mf.surf.net (8.14.3/8.14.3/Debian-9.4) with ESMTP id q57C3oZ8028385 for ; Thu, 7 Jun 2012 14:03:50 +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 q57C3mew031328 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 7 Jun 2012 14:03:48 +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 q57C3m8S020553 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 7 Jun 2012 14:03:48 +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 q57C3kR8021034 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO) for ; Thu, 7 Jun 2012 14:03:47 +0200 Mail-Followup-To: ConTeXt ML 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: 0RHjo3OQi - e7c0669dfb2f - 20120607 (trained as not-spam) X-Scanned-By: CanIt (www . roaringpenguin . com) on 194.171.167.217 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:76759 Archived-At: --===============0374874095== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="M9NhX3UHpAaciwkO" Content-Disposition: inline --M9NhX3UHpAaciwkO Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi all, 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 ... My code so far: =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 \def\definestates{\dodoubleempty\do_define_states} \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}% } \let\dummystate\empty \newcount\nstates \unexpanded\def\add_one_state#1{% \advance\nstates\plusone \the\nstates=3D>#1,% } \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 }% } \protect \starttext \definestates[mystates][foo,bar,baz] %% At this point I=E2=80=99d like \mystates_states to contain (literally) %% =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 \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 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? I=E2=80=99d be grateful for any advice Philipp PS: Yeah, I could use Lua for it but that=E2=80=99s not the question. --M9NhX3UHpAaciwkO Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) iEYEARECAAYFAk/QmQYACgkQ02lYlJYWs9L2hwCfbP+LFG207F1+GnvhwrtSAmm3 6lkAoJ7n3wAepbdYze7EeJM92qC91Ac5 =7VCz -----END PGP SIGNATURE----- --M9NhX3UHpAaciwkO-- --===============0374874095== 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 ___________________________________________________________________________________ --===============0374874095==--