From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/76769 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 18:02:32 +0200 Message-ID: <8081DB5E-972F-4734-A808-FA213429B2C7@googlemail.com> References: <20120607120526.GA4444@phlegethon> <512FF611-2B42-42FA-8539-8D3F8585E687@googlemail.com> <20120607153438.GB4444@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 1339084978 13225 80.91.229.3 (7 Jun 2012 16:02:58 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 7 Jun 2012 16:02:58 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Thu Jun 07 18:02:57 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 1ScfAe-0003cY-Fz for gctc-ntg-context-518@m.gmane.org; Thu, 07 Jun 2012 18:02:48 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id C0A9F101DD; Thu, 7 Jun 2012 18:02:47 +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 p0HpyIhXA-tT; Thu, 7 Jun 2012 18:02:46 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 043A5101E0; Thu, 7 Jun 2012 18:02:46 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id D9BE8101E0 for ; Thu, 7 Jun 2012 18:02:44 +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 WN67G9ucuQYT for ; Thu, 7 Jun 2012 18:02:43 +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 DC206101DD for ; Thu, 7 Jun 2012 18:02:43 +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 q57G2g4x030828 for ; Thu, 7 Jun 2012 18:02:43 +0200 Original-Received: by bkcjm19 with SMTP id jm19so1011901bkc.14 for ; Thu, 07 Jun 2012 09:02:42 -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=aF6u4Xy3ne8XgIStH8G/C1wcWdkjdT0AP6zDAYktD68=; b=weyxiDaeZjnDqx1tX4BrYP3/ccbAyCO2X9EuTUaHhr8pIOIfcLgXx83M92yv7u+Ah3 vJRRxlrU0lAg52us0x/VkH4jOBA66uPoEWwu/SXQwWoenQ8oBtT3hgYW0pWNNjaymX71 LP8e0Xpc4pHf5LEMEIL+OLWDNz0SZGaod7o7QTZ7zAxJrLJEXidHPN6suKiWy3CRlTcR UMZ43aC7BQnan/7Gakh82sCG92HQWXFVBSVAp1+dTZ2RSn8zuxzDbEAHaZI8cdPEFCV6 /P0f58IMLFDpqVbQxlds6aqltc5r5MQLKh4wvEyxswUDZwugJZztxcHfx0TFPzy5v2GP s3JQ== Original-Received: by 10.204.155.131 with SMTP id s3mr2076721bkw.124.1339084962495; Thu, 07 Jun 2012 09:02:42 -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 e20sm4432539bkv.10.2012.06.07.09.02.38 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 07 Jun 2012 09:02:41 -0700 (PDT) In-Reply-To: <20120607153438.GB4444@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: 0RHjs2Guf - d8a4a153ba0e - 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:76769 Archived-At: Am 07.06.2012 um 17:34 schrieb Philipp Gesang: > Hi Wolfgang! > = > =B7=B7=B7=B7=B7=B7= =B7=B7=B7 > = >> = >> 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} > = > Thanks very much. This solves my problem. Very convenient that I > can rewrite it to use comma command. You can also try to use a Lua variant. \def\states_entry_indeed[#1][#2]% {\startlua local entries =3D utilities.parsers.settings_to_array("#1") local entry =3D entries[#2] if entry then context(entry) else context("\\tttf NO ENTRY!") end \stoplua} 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 ___________________________________________________________________________= ________