From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/76760 Path: news.gmane.org!not-for-mail From: Wolfgang Schuster Newsgroups: gmane.comp.tex.context Subject: Re: expansion and \processaction Date: Thu, 7 Jun 2012 14:32:18 +0200 Message-ID: <512FF611-2B42-42FA-8539-8D3F8585E687@googlemail.com> References: <20120607120526.GA4444@phlegethon> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 (Apple Message framework v1278) Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1339072367 29270 80.91.229.3 (7 Jun 2012 12:32:47 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 7 Jun 2012 12:32:47 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Thu Jun 07 14:32:45 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 1ScbtE-0006B2-23 for gctc-ntg-context-518@m.gmane.org; Thu, 07 Jun 2012 14:32:36 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id E8B1C101E4; Thu, 7 Jun 2012 14:32:31 +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 LEJOjZxrJeWm; Thu, 7 Jun 2012 14:32:26 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 6255D101E0; Thu, 7 Jun 2012 14:32:26 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 4CBE4101E0 for ; Thu, 7 Jun 2012 14:32:25 +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 AIIqST+4rlVR for ; Thu, 7 Jun 2012 14:32:24 +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 54039101DD for ; Thu, 7 Jun 2012 14:32:24 +0200 (CEST) Original-Received: from mail-bk0-f41.google.com (mail-bk0-f41.google.com [209.85.214.41]) by filter1-til.mf.surf.net (8.14.3/8.14.3/Debian-9.4) with ESMTP id q57CWN1W021334 for ; Thu, 7 Jun 2012 14:32:23 +0200 Original-Received: by bkcjm19 with SMTP id jm19so717570bkc.14 for ; Thu, 07 Jun 2012 05:32:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to:x-mailer; bh=mFQohSoOBOcxsjUqnKAjIDrElAuZz0QIXdieiSc9T3U=; b=rmumdCpUHay8vkNbK5UEmE70OBXIkK+MpNfTomT+B9GoFW4d/8dvVj7+hhWlq6OaEj B7iwiFqVV+/7ynTIkuOMoZ0h9xqLFAZpDabR0hwg8cQhsZhVXt3FU9xjoJ4eKmw51Edz Mqj8s8gfA82fZjVQbWnn++1eIj8liIbi+n9oZnymDMXjM/jVDpF4VQ3yAbGIjDIG5BYZ A5EH6R8lD2xRbralxwP7C4pKP3vabM+CG0m2pQphN1k2UH4pJOPy7dCOMfD6vLgNOaM0 ctwO5vBcHnSEsOVs7JlHsj/nYk36TDGJAcvIaok2TOPsos/rKmjPeh8fJM1HkbRSIyIY cWOA== Original-Received: by 10.204.155.92 with SMTP id r28mr1449087bkw.130.1339072342803; Thu, 07 Jun 2012 05:32:22 -0700 (PDT) Original-Received: from [192.168.2.36] (p57AFBF1F.dip.t-dialin.net. [87.175.191.31]) by mx.google.com with ESMTPS id n17sm3605077bkw.5.2012.06.07.05.32.20 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 07 Jun 2012 05:32:21 -0700 (PDT) In-Reply-To: <20120607120526.GA4444@phlegethon> X-Mailer: Apple Mail (2.1278) X-Bayes-Prob: 0.0001 (Score 0, tokens from: @@RPTN) X-CanIt-Geo: ip=209.85.214.41; country=US; region=CA; city=Mountain View; postalcode=94043; latitude=37.4192; longitude=-122.0574; metrocode=807; areacode=650; http://maps.google.com/maps?q=37.4192,-122.0574&z=6 X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 0RHjownwn - d1982a4590fd - 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:76760 Archived-At: Am 07.06.2012 um 14:05 schrieb Philipp Gesang: > 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=92t consider expansion ... > = > My code so far: > = > =B7=B78<=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7= =B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7= =B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=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=92d like \mystates_states to contain (literally) > %% =931=3D>foo,2=3D>bar,3=3D>baz,unknown=3D>,default=3D>,=94 > %% 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 > =B7=B78<=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7= =B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7= =B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=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? \unprotect \unexpanded\def\definestates {\dodoubleargument\definestates_indeed} \def\definestates_indeed[#1][#2]% {\setuevalue{#1}{\states_entry[#2]}} \unexpanded\def\states_entry {\dodoubleargument\states_entry_indeed} \def\states_entry_indeed[#1][#2]% {\getcommalistsize[#1]% \ifnum#2>\commalistsize {\tttf NO ENTRY!}% \else \getfromcommalist[#1][#2]\commalistelement \fi} \protect \starttext \definestates[mystates][foo,bar,baz] \starttabulate \NC 2 \EQ \mystates [2] \NC\NR \NC 42 \EQ \mystates[42] \NC\NR \stoptabulate \stoptext Wolfgang ___________________________________________________________________________= ________ If your question is of interest to others as well, please add an entry to t= he Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-cont= ext webpage : http://www.pragma-ade.nl / http://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________= ________