Received: from mail.proteosys.com ([213.139.130.197]) by nummer-3.proteosys with Microsoft SMTPSVC(6.0.3790.3959); Tue, 11 Aug 2009 15:26:45 +0200 Received: by mail.proteosys.com (8.14.3/8.14.3) with ESMTP id n7BDQgxp014879 for ; Tue, 11 Aug 2009 15:26:42 +0200 Received: from listserv.uni-heidelberg.de (listserv.uni-heidelberg.de [129.206.100.94]) by relay.uni-heidelberg.de (8.14.1/8.14.1) with ESMTP id n7BDKbqr018514 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 11 Aug 2009 15:20:37 +0200 Received: from listserv.uni-heidelberg.de (localhost.localdomain [127.0.0.1]) by listserv.uni-heidelberg.de (8.13.1/8.13.1) with ESMTP id n7BCdJpR028140; Tue, 11 Aug 2009 15:20:36 +0200 Received: by LISTSERV.UNI-HEIDELBERG.DE (LISTSERV-TCP/IP release 15.5) with spool id 291260 for LATEX-L@LISTSERV.UNI-HEIDELBERG.DE; Tue, 11 Aug 2009 15:20:36 +0200 Received: from relay2.uni-heidelberg.de (relay2.uni-heidelberg.de [129.206.210.211]) by listserv.uni-heidelberg.de (8.13.1/8.13.1) with ESMTP id n7BDKaFl032301 for ; Tue, 11 Aug 2009 15:20:36 +0200 Received: from av9-2-sn2.hy.skanova.net (av9-2-sn2.hy.skanova.net [81.228.8.180]) by relay2.uni-heidelberg.de (8.13.8/8.13.8) with ESMTP id n7BDKRZU023661 for ; Tue, 11 Aug 2009 15:20:31 +0200 Received: by av9-2-sn2.hy.skanova.net (Postfix, from userid 502) id 4234B38348; Tue, 11 Aug 2009 15:03:46 +0200 (CEST) Received: from smtp4-1-sn2.hy.skanova.net (smtp4-1-sn2.hy.skanova.net [81.228.8.92]) by av9-2-sn2.hy.skanova.net (Postfix) with ESMTP id 152153820B for ; Tue, 11 Aug 2009 15:03:46 +0200 (CEST) Received: from Kuben.local (90-230-192-94-no86.tbcn.telia.com [90.230.192.94]) by smtp4-1-sn2.hy.skanova.net (Postfix) with ESMTP id DF5D137E4A for ; Tue, 11 Aug 2009 15:03:45 +0200 (CEST) User-Agent: Thunderbird 2.0.0.22 (Macintosh/20090605) MIME-Version: 1.0 References: <4A7921CF.5020803@morningstar2.co.uk> <4A7A1505.4040604@residenset.net> <4A7AD930.2090106@residenset.net> <8516B615-51AA-4D90-BB7D-A9E122AA0335@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by listserv.uni-heidelberg.de id n7BDKaFl032302 Message-ID: <4A816C31.9080401@residenset.net> Date: Tue, 11 Aug 2009 15:03:45 +0200 Reply-To: Mailing list for the LaTeX3 project Sender: Mailing list for the LaTeX3 project From: =?ISO-8859-1?Q?Lars_Hellstr=F6m?= Subject: Re: xparse To: LATEX-L@LISTSERV.UNI-HEIDELBERG.DE In-Reply-To: <8516B615-51AA-4D90-BB7D-A9E122AA0335@gmail.com> Precedence: list List-Help: , List-Unsubscribe: List-Subscribe: List-Owner: List-Archive: X-ProteoSys-SPAM-Score: -6.599 () BAYES_00,RCVD_IN_DNSWL_MED X-Scanned-By: MIMEDefang 2.65 on 213.139.130.197 Return-Path: owner-latex-l@LISTSERV.UNI-HEIDELBERG.DE X-OriginalArrivalTime: 11 Aug 2009 13:26:45.0554 (UTC) FILETIME=[5F512120:01CA1A87] Status: R X-Status: X-Keywords: X-UID: 5883 Will Robertson skrev: > Hi Lars, > > On 06/08/2009, at 10:52 PM, Lars Hellström wrote: > >> The xdoc2l3 preprocessing is more about doing things to an argument >> after you've grabbed it, than about changing the conditions under >> which it is grabbed. > > [...] > >> and refer to the scratch variables \l_tmpa_tl, \l_tmpb_tl, etc. where >> the values are needed, we can have #1, #2, etc. be these cleaned-up >> values throughout the body. > > [...] > >> Just bear in mind that what seems esoteric today may be standard >> practice for the programming technique you'll learn tomorrow. > > Sorry for the slow reply; your idea finally clicked in my brain a few > days ago and the idea has kinda stuck. Well, I've been slow on reading as well, mostly for weather-related reasons. > So let's say we want to define \foo that takes an argument but has to > sanitise it in some way before processing it: > > \DeclareDocumentCommand \foo {m} { > \my_sanitise:Nn \l_sanitised_tl {#1} > \foo_internal:V \l_sanitised_tl > } > \cs_new:Nn \my_sanitise:Nn { > % do something with #1 and save it in \l_sanitised_tl The #1 of \foo, yes. > } > \cs_new:Nn \foo_internal:n { > % do whatever \foo is supposed to do with #1 Which may make use of #1 in several places, some of which may be smack in the middle of a complex call of some other user-level command, whose implementation we know very little about... > } > \cs_generate_variant:Nn \foo_internal:n {V} I thought O was the appropriate variant for expanding a token list control sequence? > From my not in-depth understanding of xdoc2l3, this can be dramatically > simplified (I imagine) with something like > > \DeclareDocumentCommand \foo { ?{\my_sanitise:n} } { > % do whatever \foo is supposed to do with #1 > } Yes. The way I coded it, you would have to declare something as a "processor", and then be free to combine said processor with other processors in the specification of an argument; the reason for this was partly that processors would leave their result "up ahead" as a mandatory argument that the next processor could operate on. For example, the processing of an (x,y) argument (xparse "c") would probably be in two steps: (x,y) grab and handle delimiters {x,y} split at comma {{x}{y}} The most general-purpose processor I defined was "x", but unfortunately the in-source description of that seems to be wrong (copied from "t" and only partially rewritten). I believe I gave a more user-oriented description in a posting to LATEX-L, however. > Just to confirm -- have I got this thing sort of right? :) > > With this sort of example, it seems pretty clear that this can save a > lot of code that's just shuffling arguments around. (In the same way > that manual optional argument processing consists of lots of > intermediate functions that simply pass their arguments around.) Exactly! I might add, that with some processing at argument-grabbing time, it also becomes interesting to do some argument checking and error reporting there: it is easier to understand _where_ a mandatory coordinate argument was expected if you get an error message where the token stream is cut off at precisely the position where the coordinate was expected. Lars Hellström PS: Just to be clear, I don't particularly like (x,y) arguments, but in this posting they made a good example.