From mboxrd@z Thu Jan 1 00:00:00 1970 From: Catonano Subject: Re: Bug in my WIP-npm-importer with blacklist Date: Mon, 26 Nov 2018 20:39:30 +0100 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000c9cf89057b967e6f" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:44586) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gRMjU-0007dq-Dy for guix-devel@gnu.org; Mon, 26 Nov 2018 14:39:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gRMjT-0003jC-9P for guix-devel@gnu.org; Mon, 26 Nov 2018 14:39:48 -0500 Received: from mail-yw1-xc29.google.com ([2607:f8b0:4864:20::c29]:40884) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gRMjT-0003j4-34 for guix-devel@gnu.org; Mon, 26 Nov 2018 14:39:47 -0500 Received: by mail-yw1-xc29.google.com with SMTP id r130so4901690ywg.7 for ; Mon, 26 Nov 2018 11:39:46 -0800 (PST) In-Reply-To: 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 --000000000000c9cf89057b967e6f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Il giorno dom 25 nov 2018 alle ore 14:21 swedebugia ha scritto: > Hi > > I am still a novice in guile so I humbly ask for help with this error > trying to get the blacklisting to work: > > sdb@komputilo ~$ ~/guix-tree/pre-inst-env guix import npm leaflet > ice-9/boot-9.scm:222:17: In procedure map1: > Syntax error: > /home/sdb/guix-tree/guix/import/npm.scm:304:2: source expression failed > to match any pattern in form (if (member (cut guix-name "node-" <>) > blacklist)) > > The relevant code is in npm.scm as detailed in the error above. > > The files are attached. > > Thanks in advance! > > There are 2 observations I can give The first one is that member" returns a boolean value (#t or #f) and your function can return just that, you don't need the if But even if you needed the if, you have to pass it at least 2 forms: a test and another expression whose value will be returned if the tests succeeds (that is, it evaluates to #t) In your code you are passing the if form only one expression. The only expression you are passing to the if is (member (cut guix-name "node-" <>) blacklist) if this subexpression evaluates to #t, what is the if supposed to do ? You could have written (define (blacklisted? guix-name) "Check if guix-name is blacklisted. RETURN #t if yes, else #f." (if (member (cut guix-name "node-" <>) blacklist) #t #f)) in this exaple, if the subexression evaluates to #t, the if form can return #t, which is but as you can see (this is my second observation), this formulation is a bit redundant It can be rewritten without the if at all, lie this (define (blacklisted? guix-name) "Check if guix-name is blacklisted. RETURN #t if yes, else #f." (member (cut guix-name "node-" <>) blacklist))) In this formulation, if the subexpression (member (cut guix-name "node-" <>) blacklist)) returns #t, your function will return #t, because your function returns the value off its last subform if the subexpression returns #f, of course your function will return #f That's supposedly what you wanted to achieve, isn't it ? You can achieve it without the if =F0=9F=98=8A Usually when Guile laments that a source expression doesn't match any pattern, that's because you messed up the parenses or because you passed the wrong number of subexpressions to a form Please note that in this case Guile is not denouncing that the wrong number of arguments were passed to a function Because the "if" is not a function, it's a special form (I think), and the expander tries to recognize a known "pattern" in it It fails and it gives up Hope this helps --000000000000c9cf89057b967e6f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Il giorno dom 25 nov 2018 alle= ore 14:21 swedebugia <swedebug= ia@riseup.net> ha scritto:
Hi

I am still a novice in guile so I humbly ask for help with this error
trying to get the blacklisting to work:

sdb@komputilo ~$ ~/guix-tree/pre-inst-env guix import npm leaflet
ice-9/boot-9.scm:222:17: In procedure map1:
Syntax error:
/home/sdb/guix-tree/guix/import/npm.scm:304:2: source expression failed to match any pattern in form (if (member (cut guix-name "node-" &= lt;>)
blacklist))

The relevant code is in npm.scm as detailed in the error above.

The files are attached.

Thanks in advance!


There are 2 observations I can give

The first one is that member" returns a boolean= value (#t or #f) and your function can return just that, you don't nee= d the if

But even if you needed the if, you have t= o pass it at least 2 forms: a test and another expression whose value will = be returned if the tests succeeds (that is, it evaluates to #t)
<= br>
In your code you are passing the if form only one expression.=

The only expression you are passing to the if is<= /div>

(member (cut guix-name "node-" <>)= blacklist)

if this subexpression evaluates to #t,= what is the if supposed to do ?

You could have wr= itten


(define (blacklisted? gui= x-name)
=C2=A0 "Check if guix-name is blacklisted. RETURN #t if yes= , else #f."
=C2=A0 (if (member (cut guix-name "node-" <= ;>) blacklist) #t #f))
=C2=A0
in this exaple, if the subexr= ession evaluates to #t, the if form can return #t, which is
=
but as you can see (this is my second observation), this for= mulation is a bit redundant

It can be rewritte= n without the if at all, lie this

(define (blackli= sted? guix-name)
=C2=A0 "Check if guix-name is blacklisted. RETURN = #t if yes, else #f."
=C2=A0 (member (cut guix-name "node-"= ; <>) blacklist)))


In thi= s formulation, if the subexpression

(member (cut g= uix-name "node-" <>) blacklist))

r= eturns #t, your function will return #t, because your function returns the = value off its last subform

if the subexpression re= turns #f, of course your function will return=C2=A0 #f

=
That's supposedly what you wanted to achieve, isn't it ?

You can achieve it without the if =F0=9F=98=8A
=

Usually whe= n Guile laments that a source expression doesn't match any pattern, tha= t's because you messed up the parenses or because you passed the wrong = number of subexpressions to a form

Please note that in this case Guile is not den= ouncing that the wrong number of arguments were passed to a function
<= div class=3D"gmail_quote">
Because the = "if" is not a function, it's a special form (I think), and th= e expander tries to recognize a known "pattern" in it

It fails and it g= ives up

Hope this helps
--000000000000c9cf89057b967e6f--