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.devel Subject: Re: bug#24887: procedure-sources not working Date: Wed, 01 Mar 2017 15:09:06 +0100 Message-ID: <878topgkcd.fsf@pobox.com> References: <20161105220110.GA3991@protected.rcdrun.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1488377390 556 195.159.176.226 (1 Mar 2017 14:09:50 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 1 Mar 2017 14:09:50 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) Cc: guile-devel@gnu.org, 24887@debbugs.gnu.org To: Jean Louis Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Wed Mar 01 15:09:46 2017 Return-path: Envelope-to: guile-devel@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 1cj4wh-0006jd-SB for guile-devel@m.gmane.org; Wed, 01 Mar 2017 15:09:36 +0100 Original-Received: from localhost ([::1]:46763 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cj4wi-0000Gx-SP for guile-devel@m.gmane.org; Wed, 01 Mar 2017 09:09:36 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57756) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cj4wV-0000FQ-HB for guile-devel@gnu.org; Wed, 01 Mar 2017 09:09:24 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cj4wQ-0001WW-Ia for guile-devel@gnu.org; Wed, 01 Mar 2017 09:09:23 -0500 Original-Received: from pb-sasl2.pobox.com ([64.147.108.67]:55296 helo=sasl.smtp.pobox.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cj4wQ-0001Vo-EQ for guile-devel@gnu.org; Wed, 01 Mar 2017 09:09:18 -0500 Original-Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by pb-sasl2.pobox.com (Postfix) with ESMTP id 5BDE9659AA; Wed, 1 Mar 2017 09:09:14 -0500 (EST) 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; s=sasl; bh=MImGCrtADyHeqxLQAPU2mFSwwiY=; b=QIwsOY MS55Dx6YLHaCUPQ5nXhvRBGRCDDApYL/xIWG1bPJSh9Q0a7vL+H/xnnitC2epgPM 1Pe9rg7zuzUOYoJR7e517rtD7epbmyeCi7QQ5acD8NZho/5dXuqd9oNCxDt8/7DE 72M/Fz12UrgYTNNQdaZB/OkwnXUehki228lpQ= 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; q=dns; s=sasl; b=NA27UmRsM+2wgoXmfrH8wm4YeRnl0/4V kan/qrybOkLdTRd7RT3XIS0pDKaTJPzI/IrXC0BgbaQxjo5/o2UkcgQh4fZ/UMLV HcnlqJ+LCttT1xXkeipmWK87p4hby1Mq6nbAc0WCg41mpHDEpe+k4FXRY1VT6i7p nCRTaGxud+M= Original-Received: from pb-sasl2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-sasl2.pobox.com (Postfix) with ESMTP id 53893659A9; Wed, 1 Mar 2017 09:09:14 -0500 (EST) Original-Received: from clucks (unknown [109.190.228.233]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by pb-sasl2.pobox.com (Postfix) with ESMTPSA id 42521659A8; Wed, 1 Mar 2017 09:09:13 -0500 (EST) In-Reply-To: <20161105220110.GA3991@protected.rcdrun.com> (Jean Louis's message of "Sun, 6 Nov 2016 01:01:10 +0300") X-Pobox-Relay-ID: A5EF6504-FE88-11E6-8B15-85AB91A0D1B0-02397024!pb-sasl2.pobox.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 64.147.108.67 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.21 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:18966 Archived-At: On Sat 05 Nov 2016 23:01, Jean Louis writes: > Sadly, the procedure-source is not working. This would be very useful > for programming. > > Jean > > scheme@(guile-user) [50]> (define (dosomething text) (write text)) > scheme@(guile-user) [50]> (dosomething "Hello") > "Hello"scheme@(guile-user) [50]> (procedure-source dosomething ) > $93 = #f > scheme@(guile-user) [50]> Sadly I think I am going to WONTFIX this one :/ The reason is complicated. First of all, a procedure's source only makes sense within an environment: in a module and in a lexical context, and you're not guaranteed to be able to reconstruct either of those. Also a procedure's source is expressed in some dialect via macros; what should the source be for even this simple example? Should it be: (define (dosomething text) (write text)) or (lambda (text) (write text)) And if we can't get it right (i.e., don't even know what the right answer is) for even this simple case, how can we get it right for something that uses macros or is defined by a macro? What use is it, really? Better to just be able to link back to the source location at which it was defined (we can do that) or to disassemble what it does (we can do that too). It's possible to imagine environments where you can edit the procedure's source and continue directly, but that's not Guile -- we compile away extraneous information that maybe you might would need if you edit a procedure's source (e.g. you introduce a reference to a variable bound in some outer scope that wasn't referenced before). All that said, it's possible to attach arbitrary properties to source. So consider: (define-syntax-rule (define-with-source (proc . args) body ...) (define (proc . args) ;; this is how you attach arbitrary literals as procedure ;; properties efficiently, inside source #((source . (lambda args body ...))) body ...)) (define-with-source (my-proc a b) (list a b)) (procedure-property my-proc 'source) => (lambda (a b) (list a b)) Indeed because procedure-source just looks for the 'source property on my-proc, you can do: (procedure-source my-proc) => (lambda (a b) (list a b)) Hope this helps. Not sure if we should bless a "define-with-source" in Guile; thoughts? Is it even useful at all? Andy