guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Should letrec via syntax work within eval-when (expand load eval)?


From: Mark H Weaver
Subject: Re: Should letrec via syntax work within eval-when (expand load eval)?
Date: Mon, 05 Aug 2019 13:52:02 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux)

Hi Rob,

Rob Browning <address@hidden> writes:

> Rob Browning <address@hidden> 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]