From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:470:142:3::10]:59365) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j1GbP-00011l-9y for gwl-devel@gnu.org; Mon, 10 Feb 2020 16:28:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j1GbN-0008AM-T7 for gwl-devel@gnu.org; Mon, 10 Feb 2020 16:28:23 -0500 Received: from sender4-of-o51.zoho.com ([136.143.188.51]:21118) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j1GbM-0007z0-Lv for gwl-devel@gnu.org; Mon, 10 Feb 2020 16:28:21 -0500 References: <87h801p818.fsf@elephly.net> <87h800u84z.fsf@kyleam.com> <87a75spx3i.fsf@elephly.net> <877e0vq5iy.fsf@elephly.net> <875zgfosvi.fsf@elephly.net> From: Ricardo Wurmus Subject: Re: Preparing for a new release In-reply-to: Date: Mon, 10 Feb 2020 22:28:11 +0100 Message-ID: <87zhdqnndg.fsf@elephly.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gwl-devel-bounces+kyle=kyleam.com@gnu.org Sender: "gwl-devel" To: zimoun Cc: gwl-devel@gnu.org zimoun writes: > On Mon, 10 Feb 2020 at 07:31, Ricardo Wurmus wrote: >> zimoun writes: > > >> >> * It=E2=80=99s not possible to select more than one tagged item >> >> >> >> In my test workflow I=E2=80=99m generating a bunch of inputs by map= ping over >> >> an argument list. Now the problem is that I can=E2=80=99t select a= ll of these >> >> inputs easily in a code snippet. With the syntax we have I can only >> >> select the first item following a tag. >> >> >> >> To address this I=E2=80=99ve extended the accessor syntax, so this = works now: >> >> >> >> --8<---------------cut here---------------start------------->8--- >> >> process frobnicate >> >> packages "frobnicator" >> >> inputs >> >> . genome: "hg19.fa" >> >> . samples: "a" "b" "c" >> >> outputs >> >> . "result" >> >> # { >> >> frobnicate -g {{inputs:genome}} --files {{inputs::samples}} > {{o= utputs}} >> >> } >> >> --8<---------------cut here---------------end--------------->8--- >> >> >> >> Note how {{inputs::samples}} is substituted with =E2=80=9Ca b c=E2= =80=9D. With just a >> >> single colon it would be just =E2=80=9Ca=E2=80=9D. Single colon = =3D single item; double >> >> colon =3D more than one item. >> > >> > I am confused by the syntax. >> > Well how to select the second element "b"? >> > >> > Naively, I would tempt to write {{inputs:samples:2}} or {{inputs::samp= les:2}}. >> >> There=E2=80=99s no syntax for that because you can use good ol=E2=80=99 = list processing >> (let=E2=80=99s call it =E2=80=9CListp=E2=80=9D, or perhaps =E2=80=9CLisp= =E2=80=9D=E2=80=A6) to work on this outside of >> the code snippet. > > If I understand correctly, for such cases, 3 solutions: > > 1. manually split > > inputs > . sample-1: "a" > . sample-2: "b" > . sample-3: "c" > > or 2. split elsewhere 'samples' using piece of Lisp > > or 3. use Lisp features > > inputs > . sample-1: `(list-ref ,samples 1) > . sample-2: `(list-ref ,samples 2) > . sample-3: `(list-ref ,samples 3) > > > Right? That=E2=80=99s correct, but to directly access values in the =E2=80=9Cinput= s=E2=80=9D field, though, you=E2=80=99d have to use a let binding around the definition of the code snippet, which would be uglier. So ugly in fact that I decided to write this little procedure: --8<---------------cut here---------------start------------->8--- ;; Simplify access to tagged items in lists. (define pick (case-lambda ;; First item. ((key collection) (and=3D> (memq key collection) cadr)) ;; Nth item ((n key collection) (let ((sub (and=3D> (memq key collection) (lambda (sublist) (break keyword? (cdr sublist)))))) (cond ((number? n) (and (> (length sub) n) (list-ref sub n))) ;; All items ((and (procedure? n) (eq? (procedure-name n) '*)) sub) ;; SRFI-1 accessors like "first" ((procedure? n) (n sub)) (else (error "pick: Selector not supported."))))))) --8<---------------cut here---------------end--------------->8--- Then I noticed that it=E2=80=99s really inconvenient to use let bindings in= side of fields, so I changed the =E2=80=9Cmake-process=E2=80=9D macro to allow f= or definitions inside of the fields of a process. So you can do this now: --8<---------------cut here---------------start------------->8--- process foo inputs . "something" . samples: "a" "b" "c" procedure define second-sample pick second samples: inputs . # { echo {{second-sample}} } --8<---------------cut here---------------end--------------->8--- Unfortunately, the leading dot sticks out like a wart here. We could only drop it if I manage to rewrite the code-snippet value so that it really is a procedure that will return itself when applied to zero arguments=E2=80=A6 It might be possible with some tinkering. (Note that you do need the =E2=80=9Cprocedure=E2=80=9D field name here; it = can be left off only when the last value is a code-snippet.) -- Ricardo