From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.devel Subject: Re: Should letrec via syntax work within eval-when (expand load eval)? Date: Mon, 05 Aug 2019 13:52:02 -0400 Message-ID: <87zhkn8ppe.fsf@netris.org> References: <87lfwgl1wt.fsf@trouble.defaultvalue.org> <87blx8v5s1.fsf@trouble.defaultvalue.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="120112"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) Cc: guile-devel@gnu.org To: Rob Browning Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Aug 05 19:52:26 2019 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1huh9j-000V3u-VD for guile-devel@m.gmane.org; Mon, 05 Aug 2019 19:52:24 +0200 Original-Received: from localhost ([::1]:56318 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1huh9i-0006je-FH for guile-devel@m.gmane.org; Mon, 05 Aug 2019 13:52:22 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49640) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1huh9e-0006jJ-CR for guile-devel@gnu.org; Mon, 05 Aug 2019 13:52:19 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1huh9d-0007uX-DI for guile-devel@gnu.org; Mon, 05 Aug 2019 13:52:18 -0400 Original-Received: from world.peace.net ([64.112.178.59]:60016) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1huh9d-0007u5-AV for guile-devel@gnu.org; Mon, 05 Aug 2019 13:52:17 -0400 Original-Received: from mhw by world.peace.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1huh9b-0008M8-D1; Mon, 05 Aug 2019 13:52:15 -0400 In-Reply-To: <87blx8v5s1.fsf@trouble.defaultvalue.org> (Rob Browning's message of "Thu, 01 Aug 2019 18:13:02 -0500") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 64.112.178.59 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.org gmane.lisp.guile.devel:20028 Archived-At: Hi Rob, Rob Browning writes: > Rob Browning 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 without assigning or referring to the value of any . 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 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: #> 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