guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Learning the match-syntax...


From: Ricardo Wurmus
Subject: Re: Learning the match-syntax...
Date: Tue, 08 Jan 2019 21:32:35 +0100
User-agent: mu4e 1.0; emacs 26.1

swedebugia <address@hidden> 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]