unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#24887: procedure-sources not working
@ 2016-11-05 22:01 Jean Louis
  2017-03-01 14:09 ` Andy Wingo
       [not found] ` <878topgkcd.fsf@pobox.com>
  0 siblings, 2 replies; 3+ messages in thread
From: Jean Louis @ 2016-11-05 22:01 UTC (permalink / raw)
  To: 24887

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]> 





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#24887: procedure-sources not working
  2016-11-05 22:01 bug#24887: procedure-sources not working Jean Louis
@ 2017-03-01 14:09 ` Andy Wingo
       [not found] ` <878topgkcd.fsf@pobox.com>
  1 sibling, 0 replies; 3+ messages in thread
From: Andy Wingo @ 2017-03-01 14:09 UTC (permalink / raw)
  To: Jean Louis; +Cc: 24887, guile-devel

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





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#24887: procedure-sources not working
       [not found] ` <878topgkcd.fsf@pobox.com>
@ 2017-03-01 14:43   ` Jean Louis
  0 siblings, 0 replies; 3+ messages in thread
From: Jean Louis @ 2017-03-01 14:43 UTC (permalink / raw)
  To: Andy Wingo; +Cc: Jean Louis, 24887, guile-devel

On Wed, Mar 01, 2017 at 03:09:06PM +0100, Andy Wingo wrote:
> On Sat 05 Nov 2016 23:01, Jean Louis <bugs@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





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-03-01 14:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-05 22:01 bug#24887: procedure-sources not working Jean Louis
2017-03-01 14:09 ` Andy Wingo
     [not found] ` <878topgkcd.fsf@pobox.com>
2017-03-01 14:43   ` Jean Louis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).