guile-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] Add inspection command "source (, src)" which shows Scheme c


From: Daniel Hartwig
Subject: Re: [PATCH] Add inspection command "source (, src)" which shows Scheme code of loaded module
Date: Mon, 1 Apr 2013 08:42:09 +0800

On 31 March 2013 20:47, Nala Ginrut <address@hidden> 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 via email to

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