unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Mark H Weaver <mhw@netris.org>
To: Rob Browning <rlb@defaultvalue.org>
Cc: guile-devel@gnu.org
Subject: Re: Should letrec via syntax work within eval-when (expand load eval)?
Date: Mon, 05 Aug 2019 13:52:02 -0400	[thread overview]
Message-ID: <87zhkn8ppe.fsf@netris.org> (raw)
In-Reply-To: <87blx8v5s1.fsf@trouble.defaultvalue.org> (Rob Browning's message of "Thu, 01 Aug 2019 18:13:02 -0500")

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



  reply	other threads:[~2019-08-05 17:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2019-08-06  1:33     ` Rob Browning

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zhkn8ppe.fsf@netris.org \
    --to=mhw@netris.org \
    --cc=guile-devel@gnu.org \
    --cc=rlb@defaultvalue.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).