unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Catonano <catonano@gmail.com>
To: swedebugia <swedebugia@riseup.net>
Cc: guix-devel <guix-devel@gnu.org>
Subject: Re: Bug in my WIP-npm-importer with blacklist
Date: Mon, 26 Nov 2018 21:20:34 +0100	[thread overview]
Message-ID: <CAJ98PDwZ6Wbvb_A-2xBeD3WtjPZ=2oNiJvHBCcqb_63trYMyWw@mail.gmail.com> (raw)
In-Reply-To: <CAJ98PDwm3ZYLnZ05KfOBGg-B94+r86hcMq0tvNuk1jAjJosTzg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 5271 bytes --]

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 😊

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 <catonano@gmail.com> ha
scritto:

>
>
> Il giorno dom 25 nov 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-" <>)
>> 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 😊
>
> 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
>

[-- Attachment #2: Type: text/html, Size: 7058 bytes --]

      reply	other threads:[~2018-11-26 20:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-25 13:26 Bug in my WIP-npm-importer with blacklist swedebugia
2018-11-25 15:01 ` Gábor Boskovits
2018-11-26 19:39 ` Catonano
2018-11-26 20:20   ` Catonano [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAJ98PDwZ6Wbvb_A-2xBeD3WtjPZ=2oNiJvHBCcqb_63trYMyWw@mail.gmail.com' \
    --to=catonano@gmail.com \
    --cc=guix-devel@gnu.org \
    --cc=swedebugia@riseup.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).