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

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.