From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Andy Wingo Newsgroups: gmane.lisp.guile.bugs Subject: bug#24155: SRFI-10: Example from the manual fails to execute. Date: Sun, 07 Aug 2016 11:55:46 +0200 Message-ID: <87d1lksy1p.fsf@pobox.com> References: <87popodnci.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1470563787 25766 195.159.176.226 (7 Aug 2016 09:56:27 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 7 Aug 2016 09:56:27 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) Cc: 24155-done@debbugs.gnu.org To: Mathieu Lirzin Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Sun Aug 07 11:56:23 2016 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bWKoc-0005FU-SN for guile-bugs@m.gmane.org; Sun, 07 Aug 2016 11:56:19 +0200 Original-Received: from localhost ([::1]:51999 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bWKoZ-0005fe-HG for guile-bugs@m.gmane.org; Sun, 07 Aug 2016 05:56:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51630) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bWKoN-0005fS-Q8 for bug-guile@gnu.org; Sun, 07 Aug 2016 05:56:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bWKoM-000457-Kn for bug-guile@gnu.org; Sun, 07 Aug 2016 05:56:03 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:32815) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bWKoM-00044s-Hv for bug-guile@gnu.org; Sun, 07 Aug 2016 05:56:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bWKoM-00065Y-C1 for bug-guile@gnu.org; Sun, 07 Aug 2016 05:56:02 -0400 Resent-From: Andy Wingo Original-Sender: "Debbugs-submit" Resent-To: bug-guile@gnu.org Resent-Date: Sun, 07 Aug 2016 09:56:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 24155 X-GNU-PR-Package: guile X-GNU-PR-Keywords: Mail-Followup-To: 24155@debbugs.gnu.org, wingo@pobox.com, mthl@gnu.org Original-Received: via spool by 24155-done@debbugs.gnu.org id=D24155.147056376023392 (code D ref 24155); Sun, 07 Aug 2016 09:56:02 +0000 Original-Received: (at 24155-done) by debbugs.gnu.org; 7 Aug 2016 09:56:00 +0000 Original-Received: from localhost ([127.0.0.1]:58345 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bWKoK-00065E-EJ for submit@debbugs.gnu.org; Sun, 07 Aug 2016 05:56:00 -0400 Original-Received: from pb-sasl1.pobox.com ([64.147.108.66]:60375 helo=sasl.smtp.pobox.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bWKoH-000654-Ho for 24155-done@debbugs.gnu.org; Sun, 07 Aug 2016 05:55:59 -0400 Original-Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by pb-sasl1.pobox.com (Postfix) with ESMTP id E0E5229C05; Sun, 7 Aug 2016 05:55:53 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type:content-transfer-encoding; s=sasl; bh=sxiKtAWeLJWb /VwrZCTmJ17qmXI=; b=Rd8LnQd15Rbb2tSp0nZSzn2Apu7eW0r46s6fQ3dbwx99 jgA7lChgw2KC2KMZXmdir+UMPYo2FchioHg9lC252D54ErTycWluq1k44vVvV0Bt pzUOx9RUzmo28EgDEPiyP2IiBp8POvm4GRQISGKwKjGceXYajOoXKSEYJr6qVMY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type:content-transfer-encoding; q=dns; s=sasl; b=YZu5nA A+EOiPIEeFDn0hCck/j+UyMG1lENQtN/tZVxmzaee+ZJlZNUqU9eK8k+m5t8luiR gitFiyp574kfqEi6HE8J4+vV3wsj3BHk8K4KwK/WlwNdMO23PWeSJ/ytz7GMhpdK Ek1gXtM64/3Uk9Vfwj3QqdkXLGq9zVTotxmXk= Original-Received: from pb-sasl1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-sasl1.pobox.com (Postfix) with ESMTP id D864C29C04; Sun, 7 Aug 2016 05:55:53 -0400 (EDT) Original-Received: from clucks (unknown [88.160.190.192]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by pb-sasl1.pobox.com (Postfix) with ESMTPSA id EA05329C03; Sun, 7 Aug 2016 05:55:52 -0400 (EDT) In-Reply-To: <87popodnci.fsf@gnu.org> (Mathieu Lirzin's message of "Fri, 05 Aug 2016 03:19:09 +0200") X-Pobox-Relay-ID: 20CEEEBC-5C85-11E6-BC69-C1836462E9F6-02397024!pb-sasl1.pobox.com X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: "bug-guile" Xref: news.gmane.org gmane.lisp.guile.bugs:8334 Archived-At: Hi Mathieu, Thanks for the report. On Fri 05 Aug 2016 03:19, Mathieu Lirzin writes: > The following example from the Guile manual in subsection 7.5.9, fails > for me both on Guile master 2.1.3.94-1a1c3 and Guile 2.0.11 from Debian > Testing. > > (use-modules (srfi srfi-10)) > > (define-reader-ctor 'hash > (lambda elems > (let ((table (make-hash-table))) > (for-each (lambda (elem) > (apply hash-set! table elem)) > elems) > table))) > > (define (animal->family animal) > (hash-ref '#,(hash ("tiger" "cat") > ("lion" "cat") > ("wolf" "dog")) > animal)) > > The error is: > > While compiling expression: > ERROR: build-constant-store: unrecognized object # I replaced the text with this: We do not recommend #,() reader extensions, however, and for three reasons. First of all, this SRFI is not modular: the tag is matched by name, not as an identifier within a scope. Defining a reader extension in one part of a program can thus affect unrelated parts of a program because the tag is not scoped. Secondly, reader extensions can be hard to manage from a time perspective: when does the reader extension take effect? *Note Eval When::, for more discussion. Finally, reader extensions can easily produce objects that can=E2=80= =99t be reified to an object file by the compiler. For example if you define a reader extension that makes a hash table (*note Hash Tables::), then it will work fine when run with the interpreter, and you think you have a neat hack. But then if you try to compile your program, after wrangling with the =E2=80=98eval-when=E2=80=99 concerns mentioned above, the compi= ler will carp that it doesn=E2=80=99t know how to serialize a hash table to disk. In the specific case of hash tables, it would be possible for Guile to know how to pack hash tables into compiled files, but this doesn=E2= =80=99t work in general. What if the object you produce is an instance of a record type? Guile would then have to serialize the record type to disk too, and then what happens if the program independently loads the code that defines the record type? Does it define the same type or a different type? Guile=E2=80=99s record types are nominal, not structura= l, so the answer is not clear at all. For all of these reasons we recommend macros over reader extensions. Macros fulfill many of the same needs while preserving modular composition, and their interaction with =E2=80=98eval-when=E2=80=99 is w= ell-known. If you need brevity, instead use =E2=80=98read-hash-extend=E2=80=99 and mak= e your reader extension expand to a macro invocation. In that way we preserve scoping as much as possible. *Note Reader Extensions::. Thanks for the report, Andy