GNU bug report logs - #24887
procedure-sources not working

Previous Next

Package: guile;

Reported by: Jean Louis <bugs <at> gnu.support>

Date: Sat, 5 Nov 2016 22:03:01 UTC

Severity: normal

To reply to this bug, email your comments to 24887 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-guile <at> gnu.org:
bug#24887; Package guile. (Sat, 05 Nov 2016 22:03:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jean Louis <bugs <at> gnu.support>:
New bug report received and forwarded. Copy sent to bug-guile <at> gnu.org. (Sat, 05 Nov 2016 22:03:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Jean Louis <bugs <at> gnu.support>
To: bug-guile <at> gnu.org
Subject: procedure-sources not working
Date: Sun, 6 Nov 2016 01:01:10 +0300
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]> 




Information forwarded to bug-guile <at> gnu.org:
bug#24887; Package guile. (Wed, 01 Mar 2017 14:10:01 GMT) Full text and rfc822 format available.

Message #8 received at 24887 <at> debbugs.gnu.org (full text, mbox):

From: Andy Wingo <wingo <at> pobox.com>
To: Jean Louis <bugs <at> gnu.support>
Cc: guile-devel <at> gnu.org, 24887 <at> debbugs.gnu.org
Subject: Re: bug#24887: procedure-sources not working
Date: Wed, 01 Mar 2017 15:09:06 +0100
On Sat 05 Nov 2016 23:01, Jean Louis <bugs <at> gnu.support> 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




Information forwarded to bug-guile <at> gnu.org:
bug#24887; Package guile. (Wed, 01 Mar 2017 14:47:02 GMT) Full text and rfc822 format available.

Message #11 received at 24887 <at> debbugs.gnu.org (full text, mbox):

From: Jean Louis <bugs <at> gnu.support>
To: Andy Wingo <wingo <at> pobox.com>
Cc: guile-devel <at> gnu.org, 24887 <at> debbugs.gnu.org, Jean Louis <bugs <at> gnu.support>
Subject: Re: bug#24887: procedure-sources not working
Date: Wed, 1 Mar 2017 17:43:36 +0300
On Wed, Mar 01, 2017 at 03:09:06PM +0100, Andy Wingo wrote:
> On Sat 05 Nov 2016 23:01, Jean Louis <bugs <at> gnu.support> 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:

Thank you. I am not an advanced user of Guile. And that
procedure-source, I can compare to (SYMBOL-PLIST 'FUNCTION) in Lisp,
as I am also using CLISP.

If I have a function defined, such as RED, then I can see the source
of the function in CLISP:

(symbol-plist 'red)
(SYSTEM::DEFINITION ((DEFUN RED (FILE) (ED FILE) (LOAD FILE)) . #(NIL NIL NIL NIL ((DECLARATION OPTIMIZE DECLARATION)))) SYSTEM::DOC
 (SYSTEM::FILE ((SYSTEM::DEFUN/DEFMACRO
 #P"/home/data1/protected/.clisprc.lisp" 53 53))))

And I was simply expecting the PROCEDURE-SOURCE in Guile to behave in
similar fashion.

From documentation:

-- Scheme Procedure: procedure-source proc
 -- C Function: scm_procedure_source (proc)
     Return the source of the procedure PROC.  Returns ‘#f’ if the
     source code is not available.

So that is what I am expecting according to documentation. As I am not
developer of Guile, rather user and student, I cannot go into details,
if it should be there or not.

It is simply there and is not functioning, so it is expected to
function. Or you propose the removal, I don't mind.

Jean Louis




This bug report was last modified 8 years and 105 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.