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 21:20:34 +0100 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000007e0b6e057b97113f" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:58192) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gRNNB-0007C6-Pq for guix-devel@gnu.org; Mon, 26 Nov 2018 15:20:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gRNNA-0007g8-AR for guix-devel@gnu.org; Mon, 26 Nov 2018 15:20:49 -0500 Received: from mail-yb1-xb33.google.com ([2607:f8b0:4864:20::b33]:38401) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gRNNA-0007g0-4f for guix-devel@gnu.org; Mon, 26 Nov 2018 15:20:48 -0500 Received: by mail-yb1-xb33.google.com with SMTP id u103-v6so8063501ybi.5 for ; Mon, 26 Nov 2018 12:20:48 -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 --0000000000007e0b6e057b97113f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable because I made so many typing mistakes, I corrected my text and I'm posting it again, corrected 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 subepxression evaluates to #t, the if form can return #t, which is the second (sub)expression passed to it Of course, if the (first) subexpression evaluates to #f, then your if form will return #f, wich is the third (sub)expression passed to it 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, like 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 Il giorno lun 26 nov 2018 alle ore 20:39 Catonano ha scritto: > > > 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 th= e > expander tries to recognize a known "pattern" in it > > It fails and it gives up > > Hope this helps > --0000000000007e0b6e057b97113f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
because I made so many typing mistak= es, I corrected my text and I'm posting it again, corrected
<= br>




<= br>

There are 2 observations I can give

The= first one is that "member" returns a boolean value (#t or #f) an= d 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 (tha= t is, it evaluates to #t)

In your code you are passing the if form o= nly 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)
= =C2=A0 "Check if guix-name is blacklisted. RETURN #t if yes, else #f.&= quot;
=C2=A0 (if (member (cut guix-name "node-" <>) blac= klist) #t #f))
=C2=A0
in this exaple, if the subepxression evaluates = to #t, the if form can return #t, which is the second (sub)expression passe= d to it

Of course, if the (first) subexpression evaluates to #f, the= n your if form will return #f, wich is the third (sub)expression passed to = it

but as you can see (this is my second observation), this formulat= ion is a bit redundant

It can be rewritten without the if at all, li= ke this

(define (blacklisted? guix-name)
=C2=A0 "Check if gu= ix-name is blacklisted. RETURN #t if yes, else #f."
=C2=A0 (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 t= he subexpression returns #f, of course your function will return=C2=A0 #f
That's supposedly what you wanted to achieve, isn't it ?
<= br>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 n= ot denouncing that the wrong number of arguments were passed to a function<= br>
Because the "if" is not a function, it's a special for= m (I think), and the expander tries to recognize a known "pattern"= ; in it

It fails and it gives up

Hope this helps


<= /div>

Il giorno = lun 26 nov 2018 alle ore 20:39 Catonano <catonano@gmail.com> ha scritto:


Il giorno dom 25 no= v 2018 alle ore 14:21 swedebugia <swedebugia@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
--0000000000007e0b6e057b97113f--