unofficial mirror of bug-guix@gnu.org 
 help / color / mirror / code / Atom feed
* bug#68413: Ungexp doesn't work on deep lists
@ 2024-01-13  1:52 Justin Veilleux
  2024-01-13 11:38 ` Josselin Poiret via Bug reports for GNU Guix
  0 siblings, 1 reply; 4+ messages in thread
From: Justin Veilleux @ 2024-01-13  1:52 UTC (permalink / raw)
  To: 68413


Hi, I've been using G-expressions for some time and have always been
hindered by `ungexp` not working on deeper lists. For instance, when I
want to embed in a G-expression a list of packages, it works

>(define packages (list coreutils gnu-make ...))
>
> #~(for-each
>    (lambda (f)
>      ... do-something)
>    '#$packages)

But as soon as I use an object in which the file-like objects are
deeper, it fails

> (define packages
>         (list
>          (cons "coreutils" coreutils)
>          (cons "make" gnu-make)
>          ...))
>
> #~(for-each
>    (lambda (f)
>      ... do-something)
>    '#$packages)

If I send a patch to "fix" this, will it be usefull or is there a reason
for this behavior?

Thanks.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#68413: Ungexp doesn't work on deep lists
  2024-01-13  1:52 bug#68413: Ungexp doesn't work on deep lists Justin Veilleux
@ 2024-01-13 11:38 ` Josselin Poiret via Bug reports for GNU Guix
  2024-01-15  9:46   ` Ludovic Courtès
  0 siblings, 1 reply; 4+ messages in thread
From: Josselin Poiret via Bug reports for GNU Guix @ 2024-01-13 11:38 UTC (permalink / raw)
  To: Justin Veilleux, 68413

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

Hi Justin,

Justin Veilleux <terramorpha@cock.li> writes:

>> (define packages
>>         (list
>>          (cons "coreutils" coreutils)
>>          (cons "make" gnu-make)
>>          ...))
>>
>> #~(for-each
>>    (lambda (f)
>>      ... do-something)
>>    '#$packages)
>
> If I send a patch to "fix" this, will it be usefull or is there a reason
> for this behavior?

I think IMO that it's a bug, but it's also quite tricky to properly
traverse deep structures like this.  The bug comes from the fact that in
gexp->sexp, we traverse lists by matching the reference with (refs ...),
but that doesn't match if the reference is a pair instead.  Then, it
tries to match with ($ <gexp-input> (? self-quoting? x)), which does
match since self-quoting? apparently returns #t on a pair, whether or
not its constituents are also self-quoting.

Best,
-- 
Josselin Poiret

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 682 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#68413: Ungexp doesn't work on deep lists
  2024-01-13 11:38 ` Josselin Poiret via Bug reports for GNU Guix
@ 2024-01-15  9:46   ` Ludovic Courtès
  2024-01-15 16:28     ` Josselin Poiret via Bug reports for GNU Guix
  0 siblings, 1 reply; 4+ messages in thread
From: Ludovic Courtès @ 2024-01-15  9:46 UTC (permalink / raw)
  To: Josselin Poiret; +Cc: Justin Veilleux, 68413

Hi,

Josselin Poiret <dev@jpoiret.xyz> skribis:

> Justin Veilleux <terramorpha@cock.li> writes:
>
>>> (define packages
>>>         (list
>>>          (cons "coreutils" coreutils)
>>>          (cons "make" gnu-make)
>>>          ...))
>>>
>>> #~(for-each
>>>    (lambda (f)
>>>      ... do-something)
>>>    '#$packages)
>>
>> If I send a patch to "fix" this, will it be usefull or is there a reason
>> for this behavior?
>
> I think IMO that it's a bug, but it's also quite tricky to properly
> traverse deep structures like this.  The bug comes from the fact that in
> gexp->sexp, we traverse lists by matching the reference with (refs ...),
> but that doesn't match if the reference is a pair instead.  Then, it
> tries to match with ($ <gexp-input> (? self-quoting? x)), which does
> match since self-quoting? apparently returns #t on a pair, whether or
> not its constituents are also self-quoting.

Actually, what bug are we talking about?  It seems to work for me with
this example:

--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> (define packages `(("coreutils" ,coreutils) ("make" ,gnu-make)))
scheme@(guile-user)> ,build (scheme-file "foo" #~(begin '#$packages))
building /gnu/store/lq9gvbilv0y2nph00zxk6bn3lvcgdxqq-foo.drv...
$7 = "/gnu/store/9ryh6v80jvjv3kwx0q782h26h9gbaclj-foo"
scheme@(guile-user)> (call-with-input-file $7 get-string-all)
$8 = "(begin (quote ((\"coreutils\" \"/gnu/store/mppp9hwxizx9g9pikwcvvshb2ffxyq7p-coreutils-9.1\") (\"make\" \"/gnu/store/9fadhs5qmwl5x7f669a0v39b3ryrmmf1-make-4.3\"))))"
--8<---------------cut here---------------end--------------->8---

One of the design decisions for gexps was to ensure that substituting a
file-like object by its file name would be O(1) in most cases.

Substitution in lists as in the example above is supported, but
primarily for backward compatibility.  It should be avoided when
possible because it’s inefficient: ‘gexp->sexp’ needs to traverse the
whole list/tree in search of potential candidates.

Thanks,
Ludo’.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#68413: Ungexp doesn't work on deep lists
  2024-01-15  9:46   ` Ludovic Courtès
@ 2024-01-15 16:28     ` Josselin Poiret via Bug reports for GNU Guix
  0 siblings, 0 replies; 4+ messages in thread
From: Josselin Poiret via Bug reports for GNU Guix @ 2024-01-15 16:28 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: Justin Veilleux, 68413

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

Hi Ludo,

Ludovic Courtès <ludo@gnu.org> writes:

> Actually, what bug are we talking about?  It seems to work for me with
> this example:
>
> --8<---------------cut here---------------start------------->8---
> scheme@(guile-user)> (define packages `(("coreutils" ,coreutils) ("make" ,gnu-make)))
> scheme@(guile-user)> ,build (scheme-file "foo" #~(begin '#$packages))
> building /gnu/store/lq9gvbilv0y2nph00zxk6bn3lvcgdxqq-foo.drv...
> $7 = "/gnu/store/9ryh6v80jvjv3kwx0q782h26h9gbaclj-foo"
> scheme@(guile-user)> (call-with-input-file $7 get-string-all)
> $8 = "(begin (quote ((\"coreutils\" \"/gnu/store/mppp9hwxizx9g9pikwcvvshb2ffxyq7p-coreutils-9.1\") (\"make\" \"/gnu/store/9fadhs5qmwl5x7f669a0v39b3ryrmmf1-make-4.3\"))))"
> --8<---------------cut here---------------end--------------->8---
>
> One of the design decisions for gexps was to ensure that substituting a
> file-like object by its file name would be O(1) in most cases.
>
> Substitution in lists as in the example above is supported, but
> primarily for backward compatibility.  It should be avoided when
> possible because it’s inefficient: ‘gexp->sexp’ needs to traverse the
> whole list/tree in search of potential candidates.

Notice that OP's example uses `(("thing" . ,package)), ie. lists of
pairs and not lists of lists, as in your case!

Best,
-- 
Josselin Poiret

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 682 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-01-15 16:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-13  1:52 bug#68413: Ungexp doesn't work on deep lists Justin Veilleux
2024-01-13 11:38 ` Josselin Poiret via Bug reports for GNU Guix
2024-01-15  9:46   ` Ludovic Courtès
2024-01-15 16:28     ` Josselin Poiret via Bug reports for GNU Guix

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).