Re: [Chicken-users] Scraping the REPL?

2016-03-02 Thread Herr
On 23.01.2016 23:39, Matt Gushee wrote:
> Hi, James--
> 
> On Sat, Jan 23, 2016 at 10:51 AM, Hefferon, James S.  > wrote:
> 
> 
> Thank you for the "script" suggestion.  I apologize but I don't understand it.
> 
> 
> ​I see the problem. I had forgotten that csi has a -script option. I meant
> something entirely different - the 'script' command, which is entirely 
> independent
> of Chicken Scheme​, and is available on most if not all POSIX systems. You 
> use it
> like this:
> 
> $ script /path/to/transcript.file   # You are now in a subshell $ csi 
> #;1> [ doing whatever in Chicken ] #;N> (exit)
> ; exit from REPL $ exit # exit 
> from
> subshell
> 
> You will now have a complete transcript of your csi session, including all 
> the 
> prompts, everything you entered, and all the output. I mentioned that you 
> will 
> probably need to edit the result. That's because script captures raw 
> keystrokes - 
> e.g. if you type
> 
> (defin foo 21)
> 
> and you see you misspelled 'define', and correct it, what you get in your
> transcript will be not
> 
> (define foo 21)
> 
> but rather
> 
> (defin foo 21)^H^H ^H^H ^H^H ^H^H e foo 21)
> 

I cannot confirm this *using rlwrap*.

Detail: I am using an alias csii='rlwrap csi', and when using csi this way 
'script'
does not capture editing keystrokes.

/Str.





___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Scraping the REPL?

2016-01-24 Thread Hefferon, James S.
Thank you, Dan for the warning.

Matt, about script: that sounds like it might be perfect for me.  I do use 
Linux, as it is good for LaTeX.  Sorry for my confusion; I'll check it out.

Regards,
Jim

--
"Does not the Captain seek your advice, sir?"
"Not always," said Stephen.

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Scraping the REPL?

2016-01-24 Thread Dan Leslie

Word of warning: Babel seems to be hard-coded for Guile only; there are
several open bugs regarding Babel and Geiser regarding, for instance, it
breaking with Chicken.

-Dan

Alex Charlton  writes:

> Hi James,
>
> The best thing that I've found for creating "living" documents is Org-mode's
> Babel . It allows you to write
> code in a document which is  executed when the document is compiled, with
> the source and/or the results getting inserted into the document (which can
> be transformed to LaTeX). If your code generates images, you can even have
> them inserted, too (likely not what you're looking for, but still a cool
> feature!) However, there is one big caveat: Org-mode is an Emacs mode, so
> not only would you need to use Emacs, but so would anyone compiling the
> document. I could understand if this is too much of a barrier of entry for
> your liking.
>
> Another suggestion which seems a bit more in line with your desires would
> be to use a macro like so:
>
> (define counter (make-parameter 1))
>
> (define-syntax repl-print
>   (syntax-rules ()
> ((_ form)
>  (let ((result form))
>(printf "#;~s> ~s~%" (counter) (quote form))
>(unless (equal? result (void))
>  (print result))
>(counter (add1 (counter)))
>
> Which can then be used like so:
> (repl-print (+ 5 1))
> (repl-print (define (f x)  (+ x 1)))
> (repl-print (f 5))
>
> with e.g. something like  `csi -script foo.scm > foo.out` to produce almost
> the same output as your example. One issue this macro has is that it
> doesn't know about whitespace, so you're kind of limited to one line. You
> could work around that by using a pretty printer with a bit of padding
> magic, but it still won't give you "proper" Scheme indentation. Still, most
> REPL examples should be one-liners, I'd think (and hope for your sake ;) )
>
> Whatever you choose to do, good luck with your project! I look forward to
> seeing the result :)
>
> Alex
>
> On Sat, Jan 23, 2016 at 12:51 PM Hefferon, James S. 
> wrote:
>
>>
>> Thank you for the "script" suggestion.  I apologize but I don't understand
>> it.
>>
>> I'm looking for a way to automatically capture an interactive session, and
>> drop
>> it to a file, without cutting and pasting from a terminal or an editor.
>>  When I use
>> LaTeX to compile the book, I'd like that as part of the compilation it runs
>> Chicken's csi and captures the session, so that session can be
>> brought into the document.  (My past experience with cutting and pasting
>> is that as
>> the document changes the code samples get out of sync.  In addition, I'd
>> like that
>> if a person gets the doc off my github account and they compile the doc
>> then they
>> know their setup matches their doc.)
>>
>> That is, I'd like to feed this to csi, and then grab the transcript.
>>
>> #;1> (+ 5 1)
>> 6
>> #;2> (define (f x)
>> (+ x 1))
>> #;3> (f 5)
>> 6
>>
>> I can get LaTeX to run programs, for example to call "csi -script foo.scm
>> > foo.out".  But
>> I'm not sure if it is possible to grab the REPL without an Expect-type
>> situation.
>>
>> I understand "script" it will give me a single output, and not show the
>> REPL at all.
>> Am I missing the point (probably)?
>>
>> Thank you,
>> Jim
>> ___
>> Chicken-users mailing list
>> Chicken-users@nongnu.org
>> https://lists.nongnu.org/mailman/listinfo/chicken-users
>>
> ___
> Chicken-users mailing list
> Chicken-users@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/chicken-users



signature.asc
Description: PGP signature
___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Scraping the REPL?

2016-01-23 Thread Matt Gushee
What OS are you using? If you are on Linux, you can use the 'script'
command. You will have to edit the output a bit, but it does the job.

--
Matt Gushee

On Sat, Jan 23, 2016 at 4:29 AM, Hefferon, James S. 
wrote:

>
> I am writing a document that will include figures showing
> interactions with the Chicken interpreter.  In past documents of
> this kind, by-hand cutting and pasting has led me to have such
> illustrations be inaccurate.  So I would like those to be
> produced as part of the process of compiling the document (I am
> writing in LaTeX).
>
> Basically, I'd like to feed lines to the csi and then scrape the
> entire REPL off screen, so I can collect it and include it in
> the doc.
>
> In the past I have done some scraping of this kind with a Python
> script using an Expect module.  But it is a clunky process, with
> problems of its own.
>
> I see from the "Confirmed deviations" page that transcripts are
> not implemented.  Before I launch what is really a kludge, can I
> ask if I am missing some other option?  None of the eggs
> seemed to me to do this but maybe I missed some obvious point.
> Something that drops the entire interaction to a file would be ideal.
>
> Thank you for any help.
> Jim
> ___
> Chicken-users mailing list
> Chicken-users@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/chicken-users
>
___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Scraping the REPL?

2016-01-23 Thread Hefferon, James S.

Thank you for the "script" suggestion.  I apologize but I don't understand it.  

I'm looking for a way to automatically capture an interactive session, and drop 
it to a file, without cutting and pasting from a terminal or an editor.   When 
I use 
LaTeX to compile the book, I'd like that as part of the compilation it runs 
Chicken's csi and captures the session, so that session can be 
brought into the document.  (My past experience with cutting and pasting is 
that as 
the document changes the code samples get out of sync.  In addition, I'd like 
that
if a person gets the doc off my github account and they compile the doc then 
they
know their setup matches their doc.)

That is, I'd like to feed this to csi, and then grab the transcript.  

#;1> (+ 5 1)
6
#;2> (define (f x)
(+ x 1))
#;3> (f 5)
6

I can get LaTeX to run programs, for example to call "csi -script foo.scm > 
foo.out".  But
I'm not sure if it is possible to grab the REPL without an Expect-type 
situation.  

I understand "script" it will give me a single output, and not show the REPL at 
all.
Am I missing the point (probably)?  

Thank you,
Jim
___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Scraping the REPL?

2016-01-23 Thread Matt Welland
On Jan 23, 2016 4:50 AM, "Matt Gushee"  wrote:
>
> What OS are you using? If you are on Linux, you can use the 'script'
command. You will have to edit the output a bit, but it does the job.

+1 on using script.

A good alternative if you are an (x)emacs user is to use a shell inside
emacs: M-x shell . I'm pretty sure this works on windows also. Note
that command history is accessed via alt-p, not up arrow.

>
> --
> Matt Gushee
>
> On Sat, Jan 23, 2016 at 4:29 AM, Hefferon, James S. 
wrote:
>>
>>
>> I am writing a document that will include figures showing
>> interactions with the Chicken interpreter.  In past documents of
>> this kind, by-hand cutting and pasting has led me to have such
>> illustrations be inaccurate.  So I would like those to be
>> produced as part of the process of compiling the document (I am
>> writing in LaTeX).
>>
>> Basically, I'd like to feed lines to the csi and then scrape the
>> entire REPL off screen, so I can collect it and include it in
>> the doc.
>>
>> In the past I have done some scraping of this kind with a Python
>> script using an Expect module.  But it is a clunky process, with
>> problems of its own.
>>
>> I see from the "Confirmed deviations" page that transcripts are
>> not implemented.  Before I launch what is really a kludge, can I
>> ask if I am missing some other option?  None of the eggs
>> seemed to me to do this but maybe I missed some obvious point.
>> Something that drops the entire interaction to a file would be ideal.
>>
>> Thank you for any help.
>> Jim
>> ___
>> Chicken-users mailing list
>> Chicken-users@nongnu.org
>> https://lists.nongnu.org/mailman/listinfo/chicken-users
>
>
>
> ___
> Chicken-users mailing list
> Chicken-users@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/chicken-users
>
___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Scraping the REPL?

2016-01-23 Thread Alex Charlton
Hi James,

The best thing that I've found for creating "living" documents is Org-mode's
Babel . It allows you to write
code in a document which is  executed when the document is compiled, with
the source and/or the results getting inserted into the document (which can
be transformed to LaTeX). If your code generates images, you can even have
them inserted, too (likely not what you're looking for, but still a cool
feature!) However, there is one big caveat: Org-mode is an Emacs mode, so
not only would you need to use Emacs, but so would anyone compiling the
document. I could understand if this is too much of a barrier of entry for
your liking.

Another suggestion which seems a bit more in line with your desires would
be to use a macro like so:

(define counter (make-parameter 1))

(define-syntax repl-print
  (syntax-rules ()
((_ form)
 (let ((result form))
   (printf "#;~s> ~s~%" (counter) (quote form))
   (unless (equal? result (void))
 (print result))
   (counter (add1 (counter)))

Which can then be used like so:
(repl-print (+ 5 1))
(repl-print (define (f x)  (+ x 1)))
(repl-print (f 5))

with e.g. something like  `csi -script foo.scm > foo.out` to produce almost
the same output as your example. One issue this macro has is that it
doesn't know about whitespace, so you're kind of limited to one line. You
could work around that by using a pretty printer with a bit of padding
magic, but it still won't give you "proper" Scheme indentation. Still, most
REPL examples should be one-liners, I'd think (and hope for your sake ;) )

Whatever you choose to do, good luck with your project! I look forward to
seeing the result :)

Alex

On Sat, Jan 23, 2016 at 12:51 PM Hefferon, James S. 
wrote:

>
> Thank you for the "script" suggestion.  I apologize but I don't understand
> it.
>
> I'm looking for a way to automatically capture an interactive session, and
> drop
> it to a file, without cutting and pasting from a terminal or an editor.
>  When I use
> LaTeX to compile the book, I'd like that as part of the compilation it runs
> Chicken's csi and captures the session, so that session can be
> brought into the document.  (My past experience with cutting and pasting
> is that as
> the document changes the code samples get out of sync.  In addition, I'd
> like that
> if a person gets the doc off my github account and they compile the doc
> then they
> know their setup matches their doc.)
>
> That is, I'd like to feed this to csi, and then grab the transcript.
>
> #;1> (+ 5 1)
> 6
> #;2> (define (f x)
> (+ x 1))
> #;3> (f 5)
> 6
>
> I can get LaTeX to run programs, for example to call "csi -script foo.scm
> > foo.out".  But
> I'm not sure if it is possible to grab the REPL without an Expect-type
> situation.
>
> I understand "script" it will give me a single output, and not show the
> REPL at all.
> Am I missing the point (probably)?
>
> Thank you,
> Jim
> ___
> Chicken-users mailing list
> Chicken-users@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/chicken-users
>
___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Scraping the REPL?

2016-01-23 Thread Hefferon, James S.

Alex,  Thank you.  I have never heard of it, and I shall look into it.

Jim

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Scraping the REPL?

2016-01-23 Thread Matt Gushee
Hi, James--

On Sat, Jan 23, 2016 at 10:51 AM, Hefferon, James S. 
wrote:

>
> Thank you for the "script" suggestion.  I apologize but I don't understand
> it.
>

​I see the problem. I had forgotten that csi has a -script option. I meant
something entirely different - the 'script' command, which is entirely
independent of Chicken Scheme​, and is available on most if not all POSIX
systems. You use it like this:

$ script /path/to/transcript.file   # You are now in a subshell
$ csi
#;1>
[ doing whatever in Chicken ]
#;N> (exit)  ; exit from REPL
$ exit # exit from subshell

You will now have a complete transcript of your csi session, including all
the prompts, everything you entered, and all the output. I mentioned that
you will probably need to edit the result. That's because script captures
raw keystrokes - e.g. if you type

   (defin foo 21)

and you see you misspelled 'define', and correct it, what you get in your
transcript will be not

   (define foo 21)

but rather

   (defin foo 21)^H^H
^H^H
^H^H
^H^H
e foo 21)

script also, for some reason, adds a carriage return at the end of every
line, which you may not want. There is apparently no way to change that
behavior. But it does capture your entire session.

​Hope your project goes well.​
___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Scraping the REPL?

2016-01-23 Thread Matt Welland
Unless you need it's ability to capture all input you might be able to get
away without using script and just use simple scripting:

matt@xena:/mfs/matt/nodemcu/esptool$ (csi -q<< EOF
(define (f x)(+ x 123))
(f 8)
EOF
 ) > example1.txt

matt@xena:/mfs/matt/nodemcu/esptool$ cat example1.txt
csi> (define (f x)(+ x 123))
csi> (f 8) 131
csi>


On Sat, Jan 23, 2016 at 3:39 PM, Matt Gushee  wrote:

> Hi, James--
>
> On Sat, Jan 23, 2016 at 10:51 AM, Hefferon, James S. 
> wrote:
>
>>
>> Thank you for the "script" suggestion.  I apologize but I don't
>> understand it.
>>
>
> ​I see the problem. I had forgotten that csi has a -script option. I meant
> something entirely different - the 'script' command, which is entirely
> independent of Chicken Scheme​, and is available on most if not all POSIX
> systems. You use it like this:
>
> $ script /path/to/transcript.file   # You are now in a subshell
> $ csi
> #;1>
> [ doing whatever in Chicken ]
> #;N> (exit)  ; exit from REPL
> $ exit # exit from subshell
>
> You will now have a complete transcript of your csi session, including all
> the prompts, everything you entered, and all the output. I mentioned that
> you will probably need to edit the result. That's because script captures
> raw keystrokes - e.g. if you type
>
>(defin foo 21)
>
> and you see you misspelled 'define', and correct it, what you get in your
> transcript will be not
>
>(define foo 21)
>
> but rather
>
>(defin foo 21)^H^H
> ^H^H
> ^H^H
> ^H^H
> e foo 21)
>
> script also, for some reason, adds a carriage return at the end of every
> line, which you may not want. There is apparently no way to change that
> behavior. But it does capture your entire session.
>
> ​Hope your project goes well.​
>
>
> ___
> Chicken-users mailing list
> Chicken-users@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/chicken-users
>
>
___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users