[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ice-9 match penalty depending on pattern?
From: |
Simon Tournier |
Subject: |
Re: ice-9 match penalty depending on pattern? |
Date: |
Wed, 07 Feb 2024 10:22:03 +0100 |
Hi,
On mer., 07 févr. 2024 at 10:41, Carlo Zancanaro <carlo@zancanaro.id.au> wrote:
>> Why not? Do I miss something in the implementation of ’match’?
>
> The only reason I can think of would be if these matches are sometimes
> provided improper lists, which need to fail these match conditions. That
> seems unlikely to me, but it should be clear from looking at the other
> match clauses in each case.
Well, I have not pruned the list returned by just grepping. :-) And I
have just grepped with the term ’head’, ’tail’ and ’\.\.\.’
Somehow, my question is twofold:
1. Is the “expensive” check worth for such case:
(match paths
((head tail ...)
(if (visited? head)
(loop tail visited result)
(call-with-values
(lambda ()
(loop (references store head)
(visit head)
result))
(lambda (visited result)
(loop tail
visited
(cons head result))))))
(()
(values visited result)))))
seen in ’topologically-sorted’ procedure from (guix store) module.
2. Is the “expensive” check worth for such multi-cases:
(match sexp
((? string? str)
(let ((prefix "swh:1:dir:"))
(if (string-prefix? prefix str)
(cons (string-drop str (string-length prefix)) ids)
ids)))
((head tail ...)
(loop tail (loop head ids)))
(_ ids))
seen in ’lookup-disarchive-spec’ from (guix lint).
Well, I am not saying to rely on ’car’ and ’cdr’. Instead, I am asking
what is the idiomatic Guile pattern matching for Guile?
My main concern is about chasing the unnecessary checks for making Guix
a bit faster. :-)
Cheers,
simon