bug-guix
[Top][All Lists]
Advanced

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

bug#24450: [PATCHv2] Re: pypi importer outputs strange character series


From: Ricardo Wurmus
Subject: bug#24450: [PATCHv2] Re: pypi importer outputs strange character series in optional dependency case.
Date: Mon, 10 Jun 2019 11:23:10 +0200
User-agent: mu4e 1.2.0; emacs 26.2

Maxim Cournoyer <address@hidden> writes:

>>> +          ;; (extra) requirements.  Non-optional requirements must appear
>>> +          ;; before any section is defined.
>>> +          (if (or (eof-object? line) (section-header? line))
>>> +              (reverse result)
>>> +              (cond
>>> +               ((or (string-null? line) (comment? line))
>>> +                (loop result))
>>> +               (else
>>> +                (loop (cons (clean-requirement line)
>>> +                            result))))))))))
>>> +
>>
>> I think it would be better to use “match” here instead of nested “let”,
>> “if” and “cond”.  At least you can drop the “if” and just use cond.
>>
>> The loop let and the inner let can be merged.
>
> I'm not sure I understand; wouldn't merging the named let with the plain
> let mean adding an extra LINE argument to my LOOP procedure?  I don't
> want that.

Let’s forget about merging the nested “let”, because you would indeed
need to change a few more things.  It’s fine to keep that as it is.  But
(if … (cond …)) is not pretty.  At least it could be done in one “cond”:

    (cond
     ((or (eof-object? line) (section-header? line))
      (reverse result))
     ((or (string-null? line) (comment? line))
      (loop result))
     (else
      (loop (cons (clean-requirement line)
                  result))))

> Also, how could the above code be expressed using "match"? I'm using
> predicates which tests for (special) characters in a string; I don't see
> how the more primitive pattern language of "match" will enable me to do
> the same.

“match” has support for predicates, so you could do something like this:

    (match line
     ((or (eof-object) (? section-header?))
      (reverse result))
     ((or '() (? comment?))
      (loop result))
     (_ (loop (cons (clean-requirement line) result))))

This allows you to match “eof-object” and '() directly.  Whenever I see
“string-null?” I think it might be better to “match” on the empty list
directly.

But really, that’s up to you.  I only feel strongly about avoiding “(if
… (cond …))”.

--
Ricardo





reply via email to

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