From: Ricardo Wurmus <rekado@elephly.net>
To: swedebugia <swedebugia@riseup.net>
Cc: "guix-devel@gnu.org" <guix-devel@gnu.org>
Subject: Re: Learning the match-syntax...
Date: Tue, 08 Jan 2019 21:32:35 +0100 [thread overview]
Message-ID: <871s5m99gc.fsf@elephly.net> (raw)
In-Reply-To: <9bf31a36-3774-5dc2-8fe7-acc34e3d6a7f@riseup.net>
swedebugia <swedebugia@riseup.net> writes:
> This was exactly what I needed to understand! <3
Yay, I'm glad you found this useful!
> I went ahead and coded all morning and now I ported one of the
> medium-level procedures in guile-wikidata to use match:
>
> (define* (get-label qid
> #:key (language 'en))
> "Return STRING with label in the target language. Supports only one
> language. Defaults to \"en\"."
> (and-let* ((l "labels")
> (result (wdquery-alist (getentities-uri qid l #:languages language))))
“and-let*” doesn’t make much sense here, because “l” will never be #F.
You could use “and=>” and “match-lambda” without storing the
intermediate “result” value:
(and=> (wdquery-alist (getentities-uri qid "labels" #:languages language))
(match-lambda
((_ (entities . and-so-on)) 'whatever)))
I’d also like to advise against using *really* complicated patterns. It
may make more sense to write smaller procedures that each extract some
part of the result alist, because when a pattern inevitably fails to
match (e.g. due to changes in the remote API or your procedures) you get
very poor error messages.
--
Ricardo
prev parent reply other threads:[~2019-01-08 20:48 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-18 20:45 `guix lint' warn of GitHub autogenerated source tarballs Arun Isaac
2018-12-19 8:43 ` Pierre Neidhardt
2018-12-19 14:07 ` Ludovic Courtès
2018-12-19 14:33 ` Efraim Flashner
2018-12-19 17:43 ` Arun Isaac
2018-12-19 19:29 ` Efraim Flashner
2018-12-21 20:50 ` Ludovic Courtès
2018-12-21 21:00 ` swedebugia
2018-12-25 14:32 ` Efraim Flashner
2019-01-05 17:39 ` Ludovic Courtès
2019-01-05 21:25 ` Learning the match-syntax swedebugia
2019-01-05 22:35 ` Ricardo Wurmus
2019-01-06 21:36 ` Chris Marusich
2019-01-07 17:34 ` swedebugia
2019-01-07 22:18 ` Ricardo Wurmus
2019-01-08 8:25 ` swedebugia
2019-01-08 20:32 ` Ricardo Wurmus [this message]
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=871s5m99gc.fsf@elephly.net \
--to=rekado@elephly.net \
--cc=guix-devel@gnu.org \
--cc=swedebugia@riseup.net \
/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.