Re: G-Expressions and Scope Preservation
Hi Ludo, Ludovic Courtès writes: > Hello! > > Chris Marusich 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 signature.asc Description: PGP signature
Re: G-Expressions and Scope Preservation
Hello! Chris Marusich 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’.
Re: G-Expressions and Scope Preservation
zimoun 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 signature.asc Description: PGP signature
Re: G-Expressions and Scope Preservation
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
G-Expressions and Scope Preservation
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 = #:out>)) 7f29a4ed9240>:out>) 7f29a4ed91e0> scheme@(guile-user)> ,run-in-store (lower-object (scheme-file "example" ex)) $3 = # /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 = # /gnu/store/jaf44b767y5n2m0zd6q9qswhzv2hsy96-write-result 7fda1342e960> scheme@(guile-user)> ,run-in-store (gexp->derivation "write-ex-literally" write-ex-literally) $8 = # /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 signature.asc Description: PGP signature