[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug in my WIP-npm-importer with blacklist

From: Catonano
Subject: Re: Bug in my WIP-npm-importer with blacklist
Date: Mon, 26 Nov 2018 20:39:30 +0100

Il giorno dom 25 nov 2018 alle ore 14:21 swedebugia <address@hidden> ha scritto:

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

address@hidden ~$ ~/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-" <>)

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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]