From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andreas Rottmann Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH] Don't mix definitions and expressions in SRFI-9 Date: Tue, 08 Mar 2011 01:37:53 +0100 Message-ID: <871v2i4fby.fsf@gmx.at> References: <8762rwqk2p.fsf@gmx.at> <87mxl77un3.fsf@gnu.org> <871v2jvyr0.fsf@gnu.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1299544703 8385 80.91.229.12 (8 Mar 2011 00:38:23 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 8 Mar 2011 00:38:23 +0000 (UTC) Cc: guile-devel@gnu.org To: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Tue Mar 08 01:38:19 2011 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PwkwJ-0000aO-PB for guile-devel@m.gmane.org; Tue, 08 Mar 2011 01:38:16 +0100 Original-Received: from localhost ([127.0.0.1]:60273 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PwkwI-0000wz-Sx for guile-devel@m.gmane.org; Mon, 07 Mar 2011 19:38:14 -0500 Original-Received: from [140.186.70.92] (port=34718 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pwkw9-0000ws-Hq for guile-devel@gnu.org; Mon, 07 Mar 2011 19:38:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pwkw7-0001kL-0U for guile-devel@gnu.org; Mon, 07 Mar 2011 19:38:05 -0500 Original-Received: from mailout-de.gmx.net ([213.165.64.23]:44808) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1Pwkw6-0001jy-JY for guile-devel@gnu.org; Mon, 07 Mar 2011 19:38:02 -0500 Original-Received: (qmail invoked by alias); 08 Mar 2011 00:38:00 -0000 Original-Received: from 83-215-154-5.hage.dyn.salzburg-online.at (EHLO nathot.lan) [83.215.154.5] by mail.gmx.net (mp023) with SMTP; 08 Mar 2011 01:38:00 +0100 X-Authenticated: #3102804 X-Provags-ID: V01U2FsdGVkX1/A9QksZxPAdcivI/+BX9p9zTw0GZD5rlVu9EvRNW gR9JmBJMC5nIqs Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by nathot.lan (Postfix) with ESMTP id C8C8B3A68F; Tue, 8 Mar 2011 01:37:59 +0100 (CET) Original-Received: from nathot.lan ([127.0.0.1]) by localhost (nathot.lan [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QcsgJxJ6WVY1; Tue, 8 Mar 2011 01:37:53 +0100 (CET) Original-Received: from delenn.lan (delenn.lan [192.168.3.11]) by nathot.lan (Postfix) with ESMTP id 6BEC73A685; Tue, 8 Mar 2011 01:37:53 +0100 (CET) Original-Received: by delenn.lan (Postfix, from userid 1000) id 346EC2C00C8; Tue, 8 Mar 2011 01:37:53 +0100 (CET) In-Reply-To: <871v2jvyr0.fsf@gnu.org> ("Ludovic =?utf-8?Q?Court=C3=A8s=22'?= =?utf-8?Q?s?= message of "Mon, 07 Mar 2011 14:36:19 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-Y-GMX-Trusted: 0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 213.165.64.23 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:11825 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable ludo@gnu.org (Ludovic Court=C3=A8s) writes: > Hi, > > Andy Wingo writes: > >> On Sun 06 Mar 2011 23:26, ludo@gnu.org (Ludovic Court=C3=A8s) writes: >> >>> Andreas Rottmann writes: >>> >>>> The expansion of `define-inlinable' contained an expression, which made >>>> SRFI-9's `define-record-type' fail in non-toplevel contexts ("definiti= on >>>> used in expression context"). >>> >>> SRFI-9 says =E2=80=9CRecord-type definitions may only occur at top-leve= l=E2=80=9D, and >>> I=E2=80=99m inclined to stick to it. If we diverge, then people could = write >>> code thinking it=E2=80=99s portable SRFI-9 code while it=E2=80=99s not. >> >> Does anyone actually care about this? We provide many compatible >> extensions to standard interfaces. It seems like this would be an >> "unnecessary restriction which makes `let-record-type' seem necessary". > > OK, I lost. ;-) > > But, can we: > > 1. Document the extension. > > 2. Choose PROC-NAME such that -Wunused-toplevel won=E2=80=99t complain. > There=E2=80=99s a trick for this: if it contains white space, then > -Wunused-toplevel won=E2=80=99t complain; however, it has to be gene= rated > deterministically because it can appear in other compilation units, > so we can=E2=80=99t use =E2=80=98generate-temporaries=E2=80=99 here. > I think the attached version of the patch takes your suggestions into account. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=srfi-9-fix.diff From: Andreas Rottmann Subject: Don't mix definitions and expressions in SRFI-9 The expansion of `define-inlinable' contained an expression, which made SRFI-9's `define-record-type' fail in non-toplevel contexts ("definition used in expression context"). * module/srfi/srfi-9.scm (define-inlinable): Get rid of apparently useless expression in the expansion, so the expansion yields only definitions. At the same time, use a space in the generated names to lessen the chances of name conflicts, also avoiding -Wunused-toplevel warnings. * test-suite/tests/srfi-9.test (non-toplevel): New test verifying that `define-record-type' works in non-toplevel context as well. * doc/ref/srfi-modules.texi (SRFI-9 - define-record-type): Add subsubsection noting that Guile does not enforce top-levelness. --- doc/ref/srfi-modules.texi | 9 ++++++++- module/srfi/srfi-9.scm | 8 +++++--- test-suite/tests/srfi-9.test | 12 +++++++++++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/doc/ref/srfi-modules.texi b/doc/ref/srfi-modules.texi index bda7cbb..eab8779 100644 --- a/doc/ref/srfi-modules.texi +++ b/doc/ref/srfi-modules.texi @@ -1,6 +1,6 @@ @c -*-texinfo-*- @c This is part of the GNU Guile Reference Manual. -@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010 +@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 @c Free Software Foundation, Inc. @c See the file guile.texi for copying conditions. @@ -1927,6 +1927,13 @@ The functions created by @code{define-record-type} are ordinary top-level @code{define}s. They can be redefined or @code{set!} as desired, exported from a module, etc. +@unnumberedsubsubsec Non-toplevel Record Definitions + +The SRFI-9 specification explicitly disallows record definitions in a +non-toplevel context, such as inside @code{lambda} body or inside a +@var{let} block. However, Guile's implementation does not enforce that +restriction. + @unnumberedsubsubsec Custom Printers You may use @code{set-record-type-printer!} to customize the default printing diff --git a/module/srfi/srfi-9.scm b/module/srfi/srfi-9.scm index 80c3b60..fad570b 100644 --- a/module/srfi/srfi-9.scm +++ b/module/srfi/srfi-9.scm @@ -1,6 +1,6 @@ ;;; srfi-9.scm --- define-record-type -;; Copyright (C) 2001, 2002, 2006, 2009, 2010 Free Software Foundation, Inc. +;; Copyright (C) 2001, 2002, 2006, 2009, 2010, 2011 Free Software Foundation, Inc. ;; ;; This library is free software; you can redistribute it and/or ;; modify it under the terms of the GNU Lesser General Public @@ -69,9 +69,12 @@ ;; the macro expansion, whereas references in non-call contexts refer to ;; the procedure. Inspired by the `define-integrable' macro by Dybvig et al. (lambda (x) + ;; Use a space in the prefix to avoid potential -Wunused-toplevel + ;; warning + (define prefix (string->symbol "% ")) (define (make-procedure-name name) (datum->syntax name - (symbol-append '% (syntax->datum name) + (symbol-append prefix (syntax->datum name) '-procedure))) (syntax-case x () @@ -81,7 +84,6 @@ #`(begin (define (proc-name formals ...) body ...) - proc-name ;; unused (define-syntax name (lambda (x) (syntax-case x () diff --git a/test-suite/tests/srfi-9.test b/test-suite/tests/srfi-9.test index cf933a8..f8006c4 100644 --- a/test-suite/tests/srfi-9.test +++ b/test-suite/tests/srfi-9.test @@ -1,7 +1,7 @@ ;;;; srfi-9.test --- Test suite for Guile's SRFI-9 functions. -*- scheme -*- ;;;; Martin Grabmueller, 2001-05-10 ;;;; -;;;; Copyright (C) 2001, 2006, 2007, 2010 Free Software Foundation, Inc. +;;;; Copyright (C) 2001, 2006, 2007, 2010, 2011 Free Software Foundation, Inc. ;;;; ;;;; This library is free software; you can redistribute it and/or ;;;; modify it under the terms of the GNU Lesser General Public @@ -93,3 +93,13 @@ ;; prior to guile 1.6.9 and 1.8.1 this wan't enforced (pass-if-exception "set-y! on bar" exception:wrong-type-arg (set-y! b 99))) + +(with-test-prefix "non-toplevel" + + (define-record-type :frotz (make-frotz a b) frotz? + (a frotz-a) (b frotz-b set-frotz-b!)) + + (pass-if "construction" + (let ((frotz (make-frotz 1 2))) + (and (= (frotz-a frotz) 1) + (= (frotz-b frotz) 2))))) -- tg: (d59dd06..) t/srfi-9-fix (depends on: stable-2.0) --=-=-= Content-Type: text/plain Thanks, Rotty -- Andreas Rottmann -- --=-=-=--