unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Daniel Hartwig <mandyke@gmail.com>
To: guile-devel@gnu.org
Subject: Re: [PATCH] Add inspection command "source (, src)" which shows Scheme code of loaded module
Date: Mon, 1 Apr 2013 08:42:09 +0800	[thread overview]
Message-ID: <CAN3veRedE2xd1DV_aAEMFyZMWzDgHMOw1iOen42QJfs6rxnAfQ@mail.gmail.com> (raw)
In-Reply-To: <1364734048.2730.97.camel@Renee-desktop.suse>

On 31 March 2013 20:47, Nala Ginrut <nalaginrut@gmail.com> wrote:
> On Sat, 2013-03-30 at 17:17 -0400, Mark H Weaver wrote:
>> This strategy of reading the code is not robust.
>>
>> * It assumes that the procedure is the first datum on the specified
>>   line.  This is not generally true.
>
> Yes, I saw that. But I don't know how to get the procedure definition
> line from program-source, since there's no sufficient docs for that.
> Someone in IRC suggested me use the first datum.
> Could you point me out how to do that? ;-)
>

Use ‘source:column’ to get to the character where the definition
starts.

>>
>> * It assumes that there are no reader directives in the file (such as
>>   #!curly-infix) that affect the operation of the reader.  As is, your
>>   code will not work with any procedure that uses curly-infix.
>>
>> * It assumes that the procedure is written in Scheme.
>>
>
>
>> Also, as we discussed on IRC, it would be better to show the original
>> characters in the file instead of the sexp representation.  I want to
>> see the comments.  I want to see the programmer-chosen indentation.  If
>> they chose to use curly-infix for some expressions, I want to see that.
>> More generally, I want to see the presentation that the programmer
>> thought was most readable, i.e. the *source* code.
>>
>
> For these purposes above, I think there should be a modified 'read' to
> read the code from source file with comments.
>

There are other transformations that occur as Mark points out.  It is
far better to just return the unmodified source from the file.  As
discussed, the source file, column, line information gives you the
start, and ‘read’ can be used to locate the end:

 (let ((start (begin
                (skip-lines fp (source:line src))
                (seek fp (source:column src) SEEK_CUR)
                (ftell fp)))
       (end (begin
              (read fp)
              (ftell fp))))
   …

these two points are enough information to obtain the unmodified
source from the file.



  reply	other threads:[~2013-04-01  0:42 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-30 13:57 [PATCH] Add inspection command "source (,src)" which shows Scheme code of loaded module Nala Ginrut
2013-03-30 21:17 ` [PATCH] Add inspection command "source (, src)" " Mark H Weaver
2013-03-31  0:33   ` Daniel Hartwig
2013-03-31 12:47   ` [PATCH] Add inspection command "source (,src)" " Nala Ginrut
2013-04-01  0:42     ` Daniel Hartwig [this message]
2013-04-01  3:54       ` [PATCH] Add inspection command "source (, src)" " Mark H Weaver
2013-04-01  4:22         ` Daniel Hartwig
2013-04-01 19:12   ` Andy Wingo
2013-04-23  7:26     ` Show source code from .debug_info section (Was Re: [PATCH] Add inspection command "source (, src)" which shows Scheme code of loaded module) Nala Ginrut

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAN3veRedE2xd1DV_aAEMFyZMWzDgHMOw1iOen42QJfs6rxnAfQ@mail.gmail.com \
    --to=mandyke@gmail.com \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).