[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bug#24887: procedure-sources not working

From: Andy Wingo
Subject: Re: bug#24887: procedure-sources not working
Date: Wed, 01 Mar 2017 15:09:06 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux)

On Sat 05 Nov 2016 23:01, Jean Louis <address@hidden> 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))


  (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?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]