From: Ricardo Wurmus <rekado@elephly.net>
To: zimoun <zimon.toutoune@gmail.com>
Cc: gwl-devel@gnu.org
Subject: Re: Preparing for a new release
Date: Mon, 10 Feb 2020 22:28:11 +0100 [thread overview]
Message-ID: <87zhdqnndg.fsf@elephly.net> (raw)
In-Reply-To: <CAJ3okZ0CtaTvaGahZwsHtytf7v_x-ZpByhpAkQEnnTQ4=ie-Kw@mail.gmail.com>
zimoun <zimon.toutoune@gmail.com> writes:
> On Mon, 10 Feb 2020 at 07:31, Ricardo Wurmus <rekado@elephly.net> wrote:
>> zimoun <zimon.toutoune@gmail.com> writes:
>
>
>> >> * It’s not possible to select more than one tagged item
>> >>
>> >> In my test workflow I’m generating a bunch of inputs by mapping over
>> >> an argument list. Now the problem is that I can’t select all 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’ve 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}} > {{outputs}}
>> >> }
>> >> --8<---------------cut here---------------end--------------->8---
>> >>
>> >> Note how {{inputs::samples}} is substituted with “a b c”. With just a
>> >> single colon it would be just “a”. Single colon = single item; double
>> >> colon = 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::samples:2}}.
>>
>> There’s no syntax for that because you can use good ol’ list processing
>> (let’s call it “Listp”, or perhaps “Lisp”…) 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’s correct, but to directly access values in the “inputs” field,
though, you’d 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=> (memq key collection) cadr))
;; Nth item
((n key collection)
(let ((sub
(and=> (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’s really inconvenient to use let bindings inside
of fields, so I changed the “make-process” macro to allow for
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… It might be possible with some tinkering.
(Note that you do need the “procedure” field name here; it can be left
off only when the last value is a code-snippet.)
--
Ricardo
next prev parent reply other threads:[~2020-02-10 21:28 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-08 12:39 Preparing for a new release Ricardo Wurmus
2020-02-08 20:38 ` Kyle Meyer
2020-02-08 21:50 ` Ricardo Wurmus
2020-02-09 13:00 ` Ricardo Wurmus
2020-02-09 23:33 ` zimoun
2020-02-10 1:25 ` Kyle Meyer
2020-02-10 7:34 ` zimoun
2020-02-10 6:31 ` Ricardo Wurmus
2020-02-10 7:43 ` zimoun
2020-02-10 21:28 ` Ricardo Wurmus [this message]
2020-02-10 23:43 ` zimoun
2020-02-11 9:39 ` Ricardo Wurmus
2020-02-11 9:34 ` Ricardo Wurmus
2020-02-11 15:37 ` zimoun
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87zhdqnndg.fsf@elephly.net \
--to=rekado@elephly.net \
--cc=gwl-devel@gnu.org \
--cc=zimon.toutoune@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.