* Should letrec via syntax work within eval-when (expand load eval)? @ 2019-07-30 1:57 Rob Browning 2019-08-01 23:13 ` Rob Browning 0 siblings, 1 reply; 4+ messages in thread From: Rob Browning @ 2019-07-30 1:57 UTC (permalink / raw) To: guile-devel I narrowed down an issue I'd hit to this: ;; somefile.scm (define-syntax foo (syntax-rules () ((_ any ...) (letrec ((x y) (y 'foo)) x)))) (eval-when (expand load eval) (foo 1)) Which produces this with 2.2.4 and 2.2.6: $ guile -s somefile.scm [...] Backtrace: 7 (primitive-load "/home/rlb/src/lokke/standalone/ele.scm") In ice-9/eval.scm: 721:20 6 (primitive-eval (eval-when (expand load eval) (foo 1))) In ice-9/psyntax.scm: 1235:36 5 (expand-top-sequence ((eval-when (expand load eval) #)) …) 1182:24 4 (parse _ (("placeholder" placeholder)) ((top) #(# # …)) …) 285:10 3 (parse _ (("placeholder" placeholder)) ((top) #(# # …)) …) In ice-9/eval.scm: 619:8 2 (_ #(#<directory (guile-user) 55e5e3a3b140> #<variab…> …)) 298:34 1 (_ #(#<directory (guile-user) 55e5e3a3b140> #<variab…> …)) 227:9 0 (_ _) ice-9/eval.scm:227:9: Unbound variable: #<variable 55e5e3924d60 value: #<undefined>> but works fine without the eval-when, and I wondered if that was expected. Thanks -- Rob Browning rlb @defaultvalue.org and @debian.org GPG as of 2011-07-10 E6A9 DA3C C9FD 1FF8 C676 D2C4 C0F0 39E9 ED1B 597A GPG as of 2002-11-03 14DD 432F AE39 534D B592 F9A0 25C8 D377 8C7E 73A4 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Should letrec via syntax work within eval-when (expand load eval)? 2019-07-30 1:57 Should letrec via syntax work within eval-when (expand load eval)? Rob Browning @ 2019-08-01 23:13 ` Rob Browning 2019-08-05 17:52 ` Mark H Weaver 0 siblings, 1 reply; 4+ messages in thread From: Rob Browning @ 2019-08-01 23:13 UTC (permalink / raw) To: guile-devel Rob Browning <rlb@defaultvalue.org> writes: > I narrowed down an issue I'd hit to this: > > ;; somefile.scm > (define-syntax foo > (syntax-rules () > ((_ any ...) (letrec ((x y) (y 'foo)) x)))) > > (eval-when (expand load eval) (foo 1)) Wait, maybe that's just invalid (scheme-wise) in the first place, and it just happens to work in guile without the eval-when? -- Rob Browning rlb @defaultvalue.org and @debian.org GPG as of 2011-07-10 E6A9 DA3C C9FD 1FF8 C676 D2C4 C0F0 39E9 ED1B 597A GPG as of 2002-11-03 14DD 432F AE39 534D B592 F9A0 25C8 D377 8C7E 73A4 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Should letrec via syntax work within eval-when (expand load eval)? 2019-08-01 23:13 ` Rob Browning @ 2019-08-05 17:52 ` Mark H Weaver 2019-08-06 1:33 ` Rob Browning 0 siblings, 1 reply; 4+ messages in thread From: Mark H Weaver @ 2019-08-05 17:52 UTC (permalink / raw) To: Rob Browning; +Cc: guile-devel Hi Rob, Rob Browning <rlb@defaultvalue.org> writes: > Rob Browning <rlb@defaultvalue.org> writes: > >> I narrowed down an issue I'd hit to this: >> >> ;; somefile.scm >> (define-syntax foo >> (syntax-rules () >> ((_ any ...) (letrec ((x y) (y 'foo)) x)))) >> >> (eval-when (expand load eval) (foo 1)) > > Wait, maybe that's just invalid (scheme-wise) in the first place, and it > just happens to work in guile without the eval-when? The 'letrec' form above is indeed invalid. As the R5RS states: One restriction on 'letrec' is very important: it must be possible to evaluate each <init> without assigning or referring to the value of any <variable>. If this restriction is violated, then it is an error. The restriction is necessary because Scheme passes arguments by value rather than by name. In the most common uses of 'letrec', all the <init>s are lambda expressions and the restriction is satisfied automatically. This particular example happens to work when compiled by recent versions of Guile, but that's suboptimal. Ideally, we should report an error in this case. However, it fails, even outside of 'eval-when', when run by the interpreter: --8<---------------cut here---------------start------------->8--- mhw@jojen ~$ guile GNU Guile 2.2.6 Copyright (C) 1995-2019 Free Software Foundation, Inc. Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'. This program is free software, and you are welcome to redistribute it under certain conditions; type `,show c' for details. Enter `,help' for help. scheme@(guile-user)> (define-syntax foo (syntax-rules () ((_ any ...) (letrec ((x y) (y 'foo)) x)))) scheme@(guile-user)> (foo 1) $1 = foo scheme@(guile-user)> ,o interp #t scheme@(guile-user)> (foo 1) ice-9/eval.scm:227:9: Unbound variable: #<variable 1033520 value: #<undefined>> Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue. scheme@(guile-user) [1]> --8<---------------cut here---------------end--------------->8--- I guess that's the reason why it fails within the 'eval-when', because in that case it's using the interpreter to run the code within. Mark ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Should letrec via syntax work within eval-when (expand load eval)? 2019-08-05 17:52 ` Mark H Weaver @ 2019-08-06 1:33 ` Rob Browning 0 siblings, 0 replies; 4+ messages in thread From: Rob Browning @ 2019-08-06 1:33 UTC (permalink / raw) To: Mark H Weaver; +Cc: guile-devel Mark H Weaver <mhw@netris.org> writes: > The 'letrec' form above is indeed invalid. As the R5RS states: > > One restriction on 'letrec' is very important: it must be possible > to evaluate each <init> without assigning or referring to the value > of any <variable>. If this restriction is violated, then it is an > error. The restriction is necessary because Scheme passes > arguments by value rather than by name. In the most common uses of > 'letrec', all the <init>s are lambda expressions and the > restriction is satisfied automatically. Yeah, I'd read that originally, but not paid quite close enough attention (obviously). Switching to a wrapper lambda worked just fine. > This particular example happens to work when compiled by recent versions > of Guile, but that's suboptimal. Ideally, we should report an error in > this case. Indeed, not strictly necessary, but would have been nice, so I'd have realized more quicly that I was doing it wrong. Thanks again for the help. -- Rob Browning rlb @defaultvalue.org and @debian.org GPG as of 2011-07-10 E6A9 DA3C C9FD 1FF8 C676 D2C4 C0F0 39E9 ED1B 597A GPG as of 2002-11-03 14DD 432F AE39 534D B592 F9A0 25C8 D377 8C7E 73A4 ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-08-06 1:33 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2019-07-30 1:57 Should letrec via syntax work within eval-when (expand load eval)? Rob Browning 2019-08-01 23:13 ` Rob Browning 2019-08-05 17:52 ` Mark H Weaver 2019-08-06 1:33 ` Rob Browning
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).