From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ricardo Wurmus Subject: Re: Learning the match-syntax... Date: Tue, 08 Jan 2019 21:32:35 +0100 Message-ID: <871s5m99gc.fsf@elephly.net> References: <87pntxwqx0.fsf@gnu.org> <08635A1A-EDA5-44B0-8C8A-532F16683154@flashner.co.il> <20181219192926.GB2581@macbook41> <87imzmmwno.fsf@gnu.org> <20181225143202.GO2581@macbook41> <87zhsf2ec6.fsf@gnu.org> <878szx1nah.fsf@gmail.com> <9ee2cc12-7394-6256-7268-adc43c1a56c9@riseup.net> <87bm4s862z.fsf@elephly.net> <9bf31a36-3774-5dc2-8fe7-acc34e3d6a7f@riseup.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([209.51.188.92]:60081) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ggyIL-0000QC-4f for guix-devel@gnu.org; Tue, 08 Jan 2019 15:48:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ggyIJ-0007tV-9Y for guix-devel@gnu.org; Tue, 08 Jan 2019 15:48:17 -0500 Received: from sender-of-o53.zoho.com ([135.84.80.218]:21798) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ggyIG-0007qg-0j for guix-devel@gnu.org; Tue, 08 Jan 2019 15:48:13 -0500 In-reply-to: <9bf31a36-3774-5dc2-8fe7-acc34e3d6a7f@riseup.net> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: swedebugia Cc: "guix-devel@gnu.org" swedebugia 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)= ))) =E2=80=9Cand-let*=E2=80=9D doesn=E2=80=99t make much sense here, because = =E2=80=9Cl=E2=80=9D will never be #F. You could use =E2=80=9Cand=3D>=E2=80=9D and =E2=80=9Cmatch-lambda=E2=80=9D = without storing the intermediate =E2=80=9Cresult=E2=80=9D value: (and=3D> (wdquery-alist (getentities-uri qid "labels" #:languages language)) (match-lambda ((_ (entities . and-so-on)) 'whatever))) I=E2=80=99d 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