all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* G-Expressions and Scope Preservation
@ 2020-01-20 21:27 Chris Marusich
  2020-01-21 14:34 ` zimoun
  2020-01-22 22:22 ` Ludovic Courtès
  0 siblings, 2 replies; 5+ messages in thread
From: Chris Marusich @ 2020-01-20 21:27 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel

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

Hi Ludo,

In your paper "Code Staging in GNU Guix" [1], you use the following
example to illustrate how G-Expressions are hygienic ("they preserve
lexical scope across stages"):

(let ((gen-body (lambda (x)
                  #~(let ((x 40))
                      (+ x #$x)))))
  #~(let ((x 2))
      #$(gen-body #~x)))

You explain that it expands to something like this:

(let ((x-1bd8-0 2))
  (let ((x-4f05-0 40))
    (+ x-4f05-0 x-1bd8-0)))

However, when I write this gexp to disk, it doesn't look like that:

scheme@(guile-user)> ,use (guix)
scheme@(guile-user)> (define ex
                       (let ((gen-body (lambda (x)
                                         #~(let ((x 40))
                                             (+ x #$x)))))
                         #~(let ((x 2))
                             #$(gen-body #~x))))
scheme@(guile-user)> ex
$2 = #<gexp (let ((x 2)) #<gexp-input #<gexp (let ((x 40)) (+ x #<gexp-input #<gexp x 7f29a4ed92a0>:out>)) 7f29a4ed9240>:out>) 7f29a4ed91e0>
scheme@(guile-user)> ,run-in-store (lower-object (scheme-file "example" ex))
$3 = #<derivation /gnu/store/l8h0d3jx9wj9b1mn84bvmss4ng3dhmi5-example.drv => /gnu/store/mhlvarq8hc9c40by7sfq7yqvxvjdq7rp-example 7f299a13abe0>
scheme@(guile-user)> ,run-in-store (built-derivations (list $3))
building path(s) `/gnu/store/mhlvarq8hc9c40by7sfq7yqvxvjdq7rp-example'
$4 = #t

The file /gnu/store/mhlvarq8hc9c40by7sfq7yqvxvjdq7rp-example contains
the following expression:

(let ((x 2)) (let ((x 40)) (+ x x)))

This looks different than what I expected.  I expected something more
like what you had written in the paper.  Am I missing something?

I thought this would be an easy way to see the scope preservation in
action, but I get the feeling I've misunderstood something.  I tried
some other ways to use the gexp, and the results were similar:

scheme@(guile-user)> (define write-result
                       #~(with-output-to-file #$output
                           (lambda ()
                             (write #$ex))))
scheme@(guile-user)> (define write-ex-literally
                       #~(with-output-to-file #$output
                           (lambda ()
                             (write '#$ex))))
scheme@(guile-user)> ,run-in-store (gexp->derivation "write-result" write-result)
$7 = #<derivation /gnu/store/p2wbvzh1c07bj2hjz9h3ngyf35ncdgh0-write-result.drv => /gnu/store/jaf44b767y5n2m0zd6q9qswhzv2hsy96-write-result 7fda1342e960>
scheme@(guile-user)> ,run-in-store (gexp->derivation "write-ex-literally" write-ex-literally)
$8 = #<derivation /gnu/store/kpb7k7n36q64dv4zyjpp0s84ynmvp6z6-write-ex-literally.drv => /gnu/store/rhhm38j6yxfs0q7jrvdrv02r7zb9ai8j-write-ex-literally 7fda1342e780>
scheme@(guile-user)> 

The file /gnu/store/jaf44b767y5n2m0zd6q9qswhzv2hsy96-write-result
contained "80", and the file
/gnu/store/rhhm38j6yxfs0q7jrvdrv02r7zb9ai8j-write-ex-literally contained
the following S-Expression:

(let ((x 2)) (let ((x 40)) (+ x x)))

Can you help me to understand why I'm seeing this result instead of a
result that looks more like the one you presented in your paper?

Thank you,

Footnotes: 
[1]  https://hal.inria.fr/hal-01580582

-- 
Chris

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

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

* Re: G-Expressions and Scope Preservation
  2020-01-20 21:27 G-Expressions and Scope Preservation Chris Marusich
@ 2020-01-21 14:34 ` zimoun
  2020-01-22  6:01   ` Chris Marusich
  2020-01-22 22:22 ` Ludovic Courtès
  1 sibling, 1 reply; 5+ messages in thread
From: zimoun @ 2020-01-21 14:34 UTC (permalink / raw)
  To: Chris Marusich; +Cc: Guix Devel

Hi Chris,

My comment is not related at all, just for reference and/or curiosity. :-)
Yesterday night, I "discovered" the Unison language [1] which seems
presenting similar ideas than G-expression. Well, even I am not sure
to understand the both.
And Nix guys seems floating around [2]. ;-)

[1] https://www.unisonweb.org/docs/tour/
[2] https://www.unisonweb.org/docs/faq


I cannot wait for your presentation at FOSDEM. :-)


Cheers,
simon

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

* Re: G-Expressions and Scope Preservation
  2020-01-21 14:34 ` zimoun
@ 2020-01-22  6:01   ` Chris Marusich
  0 siblings, 0 replies; 5+ messages in thread
From: Chris Marusich @ 2020-01-22  6:01 UTC (permalink / raw)
  To: zimoun; +Cc: Guix Devel

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

zimoun <zimon.toutoune@gmail.com> writes:

> the Unison language

Thank you for sharing the link!  I only read the overview, but I can see
why this makes you think of G-Expressions.  It's always interesting to
read about how content addressability can make some problems easier.

> I cannot wait for your presentation at FOSDEM. :-)

I look forward to seeing you there!

-- 
Chris

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

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

* Re: G-Expressions and Scope Preservation
  2020-01-20 21:27 G-Expressions and Scope Preservation Chris Marusich
  2020-01-21 14:34 ` zimoun
@ 2020-01-22 22:22 ` Ludovic Courtès
  2020-01-23  6:43   ` Chris Marusich
  1 sibling, 1 reply; 5+ messages in thread
From: Ludovic Courtès @ 2020-01-22 22:22 UTC (permalink / raw)
  To: Chris Marusich; +Cc: guix-devel

Hello!

Chris Marusich <cmmarusich@gmail.com> skribis:

> In your paper "Code Staging in GNU Guix" [1], you use the following
> example to illustrate how G-Expressions are hygienic ("they preserve
> lexical scope across stages"):
>
> (let ((gen-body (lambda (x)
>                   #~(let ((x 40))
>                       (+ x #$x)))))
>   #~(let ((x 2))
>       #$(gen-body #~x)))
>
> You explain that it expands to something like this:
>
> (let ((x-1bd8-0 2))
>   (let ((x-4f05-0 40))
>     (+ x-4f05-0 x-1bd8-0)))
>
> However, when I write this gexp to disk, it doesn't look like that:

Ah ha!  That bit is still in the ‘wip-gexp-hygiene’ branch.

The reason I haven’t merged it, other than I didn’t take the time, is
that the output depends on Guile’s ‘hash’ function, which is not
necessarily stable.  Actually, it changed between 2.0 and 2.2, but I
think it’s the same in 2.2 and 3.0.  This needs to be checked, because
if it differs, then people will get different results depending on the
Guile version they use, and that’d be a serious issue.

I thought I had mentioned this before, but apparently not:

  https://lists.gnu.org/archive/html/guix-devel/2017-07/msg00181.html
  https://lists.gnu.org/archive/html/guix-devel/2017-09/msg00093.html

We should also do some more testing to make sure nothing breaks.

Ludo’.

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

* Re: G-Expressions and Scope Preservation
  2020-01-22 22:22 ` Ludovic Courtès
@ 2020-01-23  6:43   ` Chris Marusich
  0 siblings, 0 replies; 5+ messages in thread
From: Chris Marusich @ 2020-01-23  6:43 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel

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

Hi Ludo,

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

> Hello!
>
> Chris Marusich <cmmarusich@gmail.com> skribis:
>
>> In your paper "Code Staging in GNU Guix" [1], you use the following
>> example to illustrate how G-Expressions are hygienic ("they preserve
>> lexical scope across stages"):
>>
>> (let ((gen-body (lambda (x)
>>                   #~(let ((x 40))
>>                       (+ x #$x)))))
>>   #~(let ((x 2))
>>       #$(gen-body #~x)))
>>
>> You explain that it expands to something like this:
>>
>> (let ((x-1bd8-0 2))
>>   (let ((x-4f05-0 40))
>>     (+ x-4f05-0 x-1bd8-0)))
>>
>> However, when I write this gexp to disk, it doesn't look like that:
>
> Ah ha!  That bit is still in the ‘wip-gexp-hygiene’ branch.
>
> The reason I haven’t merged it, other than I didn’t take the time, is
> that the output depends on Guile’s ‘hash’ function, which is not
> necessarily stable.  Actually, it changed between 2.0 and 2.2, but I
> think it’s the same in 2.2 and 3.0.  This needs to be checked, because
> if it differs, then people will get different results depending on the
> Guile version they use, and that’d be a serious issue.
>
> I thought I had mentioned this before, but apparently not:
>
>   https://lists.gnu.org/archive/html/guix-devel/2017-07/msg00181.html
>   https://lists.gnu.org/archive/html/guix-devel/2017-09/msg00093.html
>
> We should also do some more testing to make sure nothing breaks.
>
> Ludo’.

Ah!  I see.  That explains it.  Thank you for pointing this out.  I'm
still finalizing my presentation, but if I find time after that, I might
play around with that branch.

-- 
Chris

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

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

end of thread, other threads:[~2020-01-23  6:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-20 21:27 G-Expressions and Scope Preservation Chris Marusich
2020-01-21 14:34 ` zimoun
2020-01-22  6:01   ` Chris Marusich
2020-01-22 22:22 ` Ludovic Courtès
2020-01-23  6:43   ` Chris Marusich

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.