swedebugia <[email protected]> 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