From unknown Sat Jun 21 03:10:51 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#13509 <13509@debbugs.gnu.org> To: bug#13509 <13509@debbugs.gnu.org> Subject: Status: wrong "definition in expression context" in R6RS mode Reply-To: bug#13509 <13509@debbugs.gnu.org> Date: Sat, 21 Jun 2025 10:10:51 +0000 retitle 13509 wrong "definition in expression context" in R6RS mode reassign 13509 guile submitter 13509 marco.maggi-ipsu@poste.it severity 13509 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Sun Jan 20 15:06:57 2013 Received: (at submit) by debbugs.gnu.org; 20 Jan 2013 20:06:57 +0000 Received: from localhost ([127.0.0.1]:41837 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Tx1AP-0001gN-0n for submit@debbugs.gnu.org; Sun, 20 Jan 2013 15:06:57 -0500 Received: from eggs.gnu.org ([208.118.235.92]:53216) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Tx10D-0001QG-R8 for submit@debbugs.gnu.org; Sun, 20 Jan 2013 14:56:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tx0zE-0006K7-KG for submit@debbugs.gnu.org; Sun, 20 Jan 2013 14:55:26 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-99.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RECEIVED_FROM_WINDOWS_HOST, RP_MATCHES_RCVD, USER_IN_WHITELIST autolearn=no version=3.3.2 Received: from lists.gnu.org ([208.118.235.17]:49572) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tx0zE-0006K3-Gv for submit@debbugs.gnu.org; Sun, 20 Jan 2013 14:55:24 -0500 Received: from eggs.gnu.org ([208.118.235.92]:36342) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tx0zD-00079r-Bv for bug-guile@gnu.org; Sun, 20 Jan 2013 14:55:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tx0zC-0006Ji-BM for bug-guile@gnu.org; Sun, 20 Jan 2013 14:55:23 -0500 Received: from relay-pt2.poste.it ([62.241.5.253]:35389) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tx0zB-0006JL-V2 for bug-guile@gnu.org; Sun, 20 Jan 2013 14:55:22 -0500 Received: from rapitore.luna (93.148.39.113) by relay-pt2.poste.it (8.5.142) (authenticated as marco.maggi-ipsu@poste.it) id 50FB33CA00028DBB; Sun, 20 Jan 2013 20:34:58 +0100 Original-Sender: marco.maggi-ipsu@poste.it Subject: wrong "definition in expression context" in R6RS mode To: bug-guile@gnu.org X-Loop: marco@maggi.it.invalid X-Mailer: GNU Emacs From: Marco Maggi Date: Sun, 20 Jan 2013 20:37:03 +0100 Message-ID: <87obgjfxy8.fsf@rapitore.luna> Lines: 30 MIME-Version: 1.0 Content-Type: text/plain X-detected-operating-system: by eggs.gnu.org: Windows NT kernel [generic] [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 208.118.235.17 X-Spam-Score: -4.2 (----) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Sun, 20 Jan 2013 15:06:55 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list Reply-To: marco.maggi-ipsu@poste.it List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -6.9 (------) On my i686-pc-linux-gnu running: $ guile --version guile (GNU Guile) 2.1.0.1329-d7cb7 built from the head of the "master" branch, this program: #!r6rs (import (rnrs)) (define (alpha) (define-syntax define-special (syntax-rules () ((_ ?who ?val) (define ?who ?val)))) (define-special beta #t) #f) (alpha) should succeed, but instead it fails with: ;;; compiling /home/marco/var/tmp/proof.sps ;;; WARNING: compilation of /home/marco/var/tmp/proof.sps failed: ;;; ERROR: Syntax error: ;;; /home/marco/var/tmp/proof.sps:12:2: definition in ;;; expression context, where definitions a re not allowed, in form (define beta #t) ice-9/boot-9.scm:718:27: In procedure map: ice-9/boot-9.scm:718:27: Syntax error: /home/marco/var/tmp/proof.sps:12:2: definition in expression context, where definitions are not allowed, in form (define beta #t) -- Marco Maggi From debbugs-submit-bounces@debbugs.gnu.org Wed Jan 23 18:50:39 2013 Received: (at 13509) by debbugs.gnu.org; 23 Jan 2013 23:50:39 +0000 Received: from localhost ([127.0.0.1]:46942 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TyA5X-0004pS-6f for submit@debbugs.gnu.org; Wed, 23 Jan 2013 18:50:39 -0500 Received: from world.peace.net ([96.39.62.75]:47125) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TyA5S-0004pJ-L6 for 13509@debbugs.gnu.org; Wed, 23 Jan 2013 18:50:36 -0500 Received: from turntable.mit.edu ([18.160.0.29] helo=tines.lan) by world.peace.net with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1TyA43-0002MB-B1; Wed, 23 Jan 2013 18:49:07 -0500 From: Mark H Weaver To: marco.maggi-ipsu@poste.it Subject: Re: bug#13509: wrong "definition in expression context" in R6RS mode References: <87obgjfxy8.fsf@rapitore.luna> Date: Wed, 23 Jan 2013 18:48:46 -0500 In-Reply-To: <87obgjfxy8.fsf@rapitore.luna> (Marco Maggi's message of "Sun, 20 Jan 2013 20:37:03 +0100") Message-ID: <87libjo3z5.fsf@tines.lan> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: 0.8 (/) X-Debbugs-Envelope-To: 13509 Cc: 13509@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -1.9 (-) --=-=-= Content-Type: text/plain Marco Maggi writes: > #!r6rs > (import (rnrs)) > (define (alpha) > (define-syntax define-special > (syntax-rules () > ((_ ?who ?val) > (define ?who ?val)))) > (define-special beta #t) > #f) > (alpha) > > should succeed, but instead it fails with: [...] > /home/marco/var/tmp/proof.sps:12:2: definition in expression context, where definitions are not allowed, in form (define beta #t) I've attached two patches for stable-2.0. The second patch fixes this bug. The first patch is for an unrelated bug that I discovered during my investigation. Reviews solicited, otherwise I'll commit these in a week or so. Mark --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Fix-source-annotation-bug-in-psyntax-expand-body.patch Content-Description: [PATCH 1/2] Fix source annotation bug in psyntax 'expand-body' >From 2b8587d090d13f044f3cc4d221e832a655dcc1cd Mon Sep 17 00:00:00 2001 From: Mark H Weaver Date: Wed, 23 Jan 2013 17:27:50 -0500 Subject: [PATCH 1/2] Fix source annotation bug in psyntax 'expand-body'. * module/ice-9/psyntax.scm (expand-body): Apply source-annotation to an expression, not to the expression's compile-time environment. * module/ice-9/psyntax-pp.scm: Regenerate. --- module/ice-9/psyntax-pp.scm | 2 +- module/ice-9/psyntax.scm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/module/ice-9/psyntax-pp.scm b/module/ice-9/psyntax-pp.scm index 5dfa8c0..139c02b 100644 --- a/module/ice-9/psyntax-pp.scm +++ b/module/ice-9/psyntax-pp.scm @@ -976,7 +976,7 @@ (let ((e (cdar body)) (er (caar body))) (call-with-values (lambda () - (syntax-type e er '(()) (source-annotation er) ribcage mod #f)) + (syntax-type e er '(()) (source-annotation e) ribcage mod #f)) (lambda (type value form e w s mod) (let ((key type)) (cond ((memv key '(define-form)) diff --git a/module/ice-9/psyntax.scm b/module/ice-9/psyntax.scm index d41a0eb..4abd3c9 100644 --- a/module/ice-9/psyntax.scm +++ b/module/ice-9/psyntax.scm @@ -1457,7 +1457,7 @@ (syntax-violation #f "no expressions in body" outer-form) (let ((e (cdar body)) (er (caar body))) (call-with-values - (lambda () (syntax-type e er empty-wrap (source-annotation er) ribcage mod #f)) + (lambda () (syntax-type e er empty-wrap (source-annotation e) ribcage mod #f)) (lambda (type value form e w s mod) (case type ((define-form) -- 1.7.10.4 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0002-Do-not-defer-expansion-of-internal-define-syntax-for.patch Content-Description: [PATCH 2/2] Do not defer expansion of internal define-syntax forms >From 20e2db39b23dfd27c92cfbdd831e91eb3e2880a5 Mon Sep 17 00:00:00 2001 From: Mark H Weaver Date: Wed, 23 Jan 2013 17:49:38 -0500 Subject: [PATCH 2/2] Do not defer expansion of internal define-syntax forms. * module/ice-9/psyntax.scm (expand-body): As required by R6RS, expand the right-hand-sides of internal 'define-syntax' forms and add their transformers to the compile-time environment immediately, so that the newly-defined keywords may be used in definition context within the same lexical contour. Fixes #13509. --- module/ice-9/psyntax-pp.scm | 29 ++++++++++------------------- module/ice-9/psyntax.scm | 36 +++++++++++++++--------------------- 2 files changed, 25 insertions(+), 40 deletions(-) diff --git a/module/ice-9/psyntax-pp.scm b/module/ice-9/psyntax-pp.scm index 139c02b..a0d338c 100644 --- a/module/ice-9/psyntax-pp.scm +++ b/module/ice-9/psyntax-pp.scm @@ -991,15 +991,17 @@ (cons (cons er (wrap e w mod)) vals) (cons (cons 'lexical var) bindings))))) ((memv key '(define-syntax-form define-syntax-parameter-form)) - (let ((id (wrap value w mod)) (label (gen-label))) + (let ((id (wrap value w mod)) + (label (gen-label)) + (trans-r (macros-only-env er))) (extend-ribcage! ribcage id label) - (parse (cdr body) - (cons id ids) - (cons label labels) - var-ids - vars - vals - (cons (cons 'macro (cons er (wrap e w mod))) bindings)))) + (set-cdr! + r + (extend-env + (list label) + (list (cons 'macro (eval-local-transformer (expand e trans-r w mod) mod))) + (cdr r))) + (parse (cdr body) (cons id ids) labels var-ids vars vals bindings))) ((memv key '(begin-form)) (let* ((tmp-1 e) (tmp ($sc-dispatch tmp-1 '(_ . each-any)))) (if tmp @@ -1049,17 +1051,6 @@ #f "invalid or duplicate identifier in definition" outer-form)) - (let loop ((bs bindings) (er-cache #f) (r-cache #f)) - (if (not (null? bs)) - (let ((b (car bs))) - (if (eq? (car b) 'macro) - (let* ((er (cadr b)) - (r-cache (if (eq? er er-cache) r-cache (macros-only-env er)))) - (set-cdr! - b - (eval-local-transformer (expand (cddr b) r-cache '(()) mod) mod)) - (loop (cdr bs) er r-cache)) - (loop (cdr bs) er-cache r-cache))))) (set-cdr! r (extend-env labels bindings (cdr r))) (build-letrec #f diff --git a/module/ice-9/psyntax.scm b/module/ice-9/psyntax.scm index 4abd3c9..980db80 100644 --- a/module/ice-9/psyntax.scm +++ b/module/ice-9/psyntax.scm @@ -1470,13 +1470,22 @@ (cons var vars) (cons (cons er (wrap e w mod)) vals) (cons (make-binding 'lexical var) bindings))))) ((define-syntax-form define-syntax-parameter-form) - (let ((id (wrap value w mod)) (label (gen-label))) + (let ((id (wrap value w mod)) + (label (gen-label)) + (trans-r (macros-only-env er))) (extend-ribcage! ribcage id label) - (parse (cdr body) - (cons id ids) (cons label labels) - var-ids vars vals - (cons (make-binding 'macro (cons er (wrap e w mod))) - bindings)))) + ;; As required by R6RS, expand the right-hand-sides of internal + ;; syntax definition forms and add their transformers to the + ;; compile-time environment immediately, so that the newly-defined + ;; keywords may be used in definition context within the same + ;; lexical contour. + (set-cdr! r (extend-env (list label) + (list (make-binding 'macro + (eval-local-transformer + (expand e trans-r w mod) + mod))) + (cdr r))) + (parse (cdr body) (cons id ids) labels var-ids vars vals bindings))) ((begin-form) (syntax-case e () ((_ e1 ...) @@ -1507,21 +1516,6 @@ (syntax-violation #f "invalid or duplicate identifier in definition" outer-form)) - (let loop ((bs bindings) (er-cache #f) (r-cache #f)) - (if (not (null? bs)) - (let* ((b (car bs))) - (if (eq? (car b) 'macro) - (let* ((er (cadr b)) - (r-cache - (if (eq? er er-cache) - r-cache - (macros-only-env er)))) - (set-cdr! b - (eval-local-transformer - (expand (cddr b) r-cache empty-wrap mod) - mod)) - (loop (cdr bs) er r-cache)) - (loop (cdr bs) er-cache r-cache))))) (set-cdr! r (extend-env labels bindings (cdr r))) (build-letrec no-source #t (reverse (map syntax->datum var-ids)) -- 1.7.10.4 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Thu Jan 31 01:11:09 2013 Received: (at 13509-done) by debbugs.gnu.org; 31 Jan 2013 06:11:10 +0000 Received: from localhost ([127.0.0.1]:56666 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1U0nMa-0003O8-2p for submit@debbugs.gnu.org; Thu, 31 Jan 2013 01:11:09 -0500 Received: from world.peace.net ([96.39.62.75]:56568) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1U0nMX-0003O0-F5 for 13509-done@debbugs.gnu.org; Thu, 31 Jan 2013 01:11:06 -0500 Received: from 209-6-91-212.c3-0.smr-ubr1.sbo-smr.ma.cable.rcn.com ([209.6.91.212] helo=tines.lan) by world.peace.net with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1U0nLl-0000yH-2O; Thu, 31 Jan 2013 01:10:17 -0500 From: Mark H Weaver To: marco.maggi-ipsu@poste.it Subject: Re: bug#13509: wrong "definition in expression context" in R6RS mode References: <87obgjfxy8.fsf@rapitore.luna> Date: Thu, 31 Jan 2013 01:10:07 -0500 In-Reply-To: <87obgjfxy8.fsf@rapitore.luna> (Marco Maggi's message of "Sun, 20 Jan 2013 20:37:03 +0100") Message-ID: <874nhxj328.fsf@tines.lan> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 13509-done Cc: 13509-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -1.9 (-) Marco Maggi writes: > #!r6rs > (import (rnrs)) > (define (alpha) > (define-syntax define-special > (syntax-rules () > ((_ ?who ?val) > (define ?who ?val)))) > (define-special beta #t) > #f) > (alpha) > > should succeed, but instead it fails with: > [...] > ;;; /home/marco/var/tmp/proof.sps:12:2: definition in > ;;; expression context, where definitions a re not allowed, in form (define beta #t) Fixed in ceb7f9cc126f50e0cc8956b80ac5d111580b23c8 (which is now in stable-2.0 but not yet in master) Thanks for the report! Mark From unknown Sat Jun 21 03:10:51 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Thu, 28 Feb 2013 12:24:03 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator