How to get a useful repl with Chicken 5?

2020-01-30 Thread Matt Welland
Line editing and saving history make using a repl much more productive for
me. With chicken 4 I was able to get a useful repl with something like this
sequence of calls:

(import extras) ;; might not be needed?
(import readline)
(import apropos)
;; my imports here ...
(install-history-file (get-environment-variable "HOME") ".some_history")
(current-input-port (make-readline-port "someprog> "))
(repl)

I've tried linenoise but don't see how to save the history:

(import linenoise)
(set-history-length! 300)
(load-history-from-file historyf)
(current-input-port (make-linenoise-port))
(repl)
;; (save-history-to-file historyf) ;; doesn't work :(

I've read the docs on linenoise and breadline but I'm not seeing how to get
a useful editable repl.

Any pointers or suggestions would be appreciated.
--
Complexity is your enemy. Any fool can make something complicated.
It is hard to keep things simple. - Richard Branson.


Re: How to get a useful repl with Chicken 5?

2020-01-30 Thread Daniel Ortmann

How about: rlwrap csi

It has been good to me, saving the history into ~/.csi_history

On 1/30/20 12:01 PM, Matt Welland wrote:
Line editing and saving history make using a repl much more productive 
for me. With chicken 4 I was able to get a useful repl with something 
like this sequence of calls:


(import extras) ;; might not be needed?
(import readline)
(import apropos)
;; my imports here ...
(install-history-file (get-environment-variable "HOME") ".some_history")
(current-input-port (make-readline-port "someprog> "))
(repl)

I've tried linenoise but don't see how to save the history:

(import linenoise)
(set-history-length! 300)
(load-history-from-file historyf)
(current-input-port (make-linenoise-port))
(repl)
;; (save-history-to-file historyf) ;; doesn't work :(

I've read the docs on linenoise and breadline but I'm not seeing how 
to get a useful editable repl.


Any pointers or suggestions would be appreciated.
--
Complexity is your enemy. Any fool can make something complicated.
It is hard to keep things simple. - Richard Branson.




Re: How to get a useful repl with Chicken 5?

2020-01-30 Thread Matt Welland
Hi Daniel, that is a good suggestion. rlwrap it is for today. Still, it
would be nice to have something that I can build into my apps as I did for
Chicken 4. Thanks.

On Thu, Jan 30, 2020 at 11:29 AM Daniel Ortmann 
wrote:

> How about: rlwrap csi
>
> It has been good to me, saving the history into ~/.csi_history
>
> On 1/30/20 12:01 PM, Matt Welland wrote:
>
> Line editing and saving history make using a repl much more productive for
> me. With chicken 4 I was able to get a useful repl with something like this
> sequence of calls:
>
> (import extras) ;; might not be needed?
> (import readline)
> (import apropos)
> ;; my imports here ...
> (install-history-file (get-environment-variable "HOME") ".some_history")
> (current-input-port (make-readline-port "someprog> "))
> (repl)
>
> I've tried linenoise but don't see how to save the history:
>
> (import linenoise)
> (set-history-length! 300)
> (load-history-from-file historyf)
> (current-input-port (make-linenoise-port))
> (repl)
> ;; (save-history-to-file historyf) ;; doesn't work :(
>
> I've read the docs on linenoise and breadline but I'm not seeing how to
> get a useful editable repl.
>
> Any pointers or suggestions would be appreciated.
> --
> Complexity is your enemy. Any fool can make something complicated.
> It is hard to keep things simple. - Richard Branson.
>
>
>

-- 
--
Complexity is your enemy. Any fool can make something complicated.
It is hard to keep things simple. - Richard Branson.


Re: How to get a useful repl with Chicken 5?

2020-01-30 Thread Vasilij Schneidermann
Hello Matt,

> I've read the docs on linenoise and breadline but I'm not seeing how to get
> a useful editable repl.
> 
> Any pointers or suggestions would be appreciated.

I've developed breadline.  Its wiki page has an examples section which
shows how to create a custom REPL for programs and points to
 for two
more examples, a `.csirc` (for your other scenario of customizing `csi`)
and how a simple completer can be created.

The story is similar with linenoise, its wiki page has an example
section for general use and a "Using linenoise in csi" one.  Did you
have issues with setting either up?

Vasilij


signature.asc
Description: PGP signature


Re: How to get a useful repl with Chicken 5?

2020-01-31 Thread Matt Welland
For linenoise I was not able to get saving history to work.

I'm having trouble getting breadline to install on Ubuntu on this old
laptop. I have libreadline-dev installed but when I do chicken-install
breadline I get:

matt@matt-HP-EliteBook-6930p:~$ chicken-install breadline
building breadline
   /home/matt/.cache/chicken-install/breadline/build-breadline -host -D
compiling-extension -J -s -regenerate-import-libraries -setup-mode -I
/home/matt/.cache/chicken-install/breadline -C
-I/home/matt/.cache/chicken-install/breadline -O2 -d1 breadline.scm -o
/home/matt/.cache/chicken-install/breadline/breadline.so
Package readline was not found in the pkg-config search path.
Perhaps you should add the directory containing `readline.pc'
to the PKG_CONFIG_PATH environment variable
No package 'readline' found
Package readline was not found in the pkg-config search path.
Perhaps you should add the directory containing `readline.pc'
to the PKG_CONFIG_PATH environment variable
No package 'readline' found
Package readline was not found in the pkg-config search path.
Perhaps you should add the directory containing `readline.pc'
to the PKG_CONFIG_PATH environment variable
No package 'readline' found
Package readline was not found in the pkg-config search path.
Perhaps you should add the directory containing `readline.pc'
to the PKG_CONFIG_PATH environment variable
No package 'readline' found
/usr/bin/ld: cannot find -lncurses
collect2: error: ld returned 1 exit status

Error: shell command terminated with non-zero exit status 256: 'gcc'
'/home/matt/.cache/chicken-install/breadline/breadline.o' -o
'/home/matt/.cache/chicken-install/breadline/breadline.so' -shared
-lreadline -lncurses -L/opt/chicken/5.1.0_WW45/lib
-Wl,-R/opt/chicken/5.1.0_WW45/lib -lchicken -lm -ldl
   /home/matt/.cache/chicken-install/breadline/build-breadline
-regenerate-import-libraries -setup-mode -static -I
/home/matt/.cache/chicken-install/breadline -emit-link-file
/home/matt/.cache/chicken-install/breadline/breadline.link -host -D
compiling-extension -c -unit breadline -D compiling-static-extension -C
-I/home/matt/.cache/chicken-install/breadline -O2 -d1 breadline.scm -o
/home/matt/.cache/chicken-install/breadline/breadline.static.o
Package readline was not found in the pkg-config search path.
Perhaps you should add the directory containing `readline.pc'
to the PKG_CONFIG_PATH environment variable
No package 'readline' found
Package readline was not found in the pkg-config search path.
Perhaps you should add the directory containing `readline.pc'
to the PKG_CONFIG_PATH environment variable
No package 'readline' found
Package readline was not found in the pkg-config search path.
Perhaps you should add the directory containing `readline.pc'
to the PKG_CONFIG_PATH environment variable
No package 'readline' found
Package readline was not found in the pkg-config search path.
Perhaps you should add the directory containing `readline.pc'
to the PKG_CONFIG_PATH environment variable
No package 'readline' found
   /opt/chicken/5.1.0_WW45/bin/csc -setup-mode -s -host -I
/home/matt/.cache/chicken-install/breadline -C
-I/home/matt/.cache/chicken-install/breadline -O2 -d0 breadline.import.scm
-o /home/matt/.cache/chicken-install/breadline/breadline.import.so
   /opt/chicken/5.1.0_WW45/bin/csc -host -D compiling-extension -J -s
-regenerate-import-libraries -setup-mode -I
/home/matt/.cache/chicken-install/breadline -C
-I/home/matt/.cache/chicken-install/breadline -O2 -d1
breadline-scheme-completion.scm -o
/home/matt/.cache/chicken-install/breadline/breadline-scheme-completion.so
   /opt/chicken/5.1.0_WW45/bin/csc -regenerate-import-libraries -setup-mode
-static -I /home/matt/.cache/chicken-install/breadline -emit-link-file
/home/matt/.cache/chicken-install/breadline/breadline-scheme-completion.link
-host -D compiling-extension -c -unit breadline-scheme-completion -D
compiling-static-extension -C -I/home/matt/.cache/chicken-install/breadline
-O2 -d1 breadline-scheme-completion.scm -o
/home/matt/.cache/chicken-install/breadline/breadline-scheme-completion.static.o
   /opt/chicken/5.1.0_WW45/bin/csc -setup-mode -s -host -I
/home/matt/.cache/chicken-install/breadline -C
-I/home/matt/.cache/chicken-install/breadline -O2 -d0
breadline-scheme-completion.import.scm -o
/home/matt/.cache/chicken-install/breadline/
breadline-scheme-completion.import.so
  installing breadline
install: cannot stat
'/home/matt/.cache/chicken-install/breadline/breadline.so': No such file or
directory

Error: shell command terminated with nonzero exit code
256
"sh /home/matt/.cache/chicken-install/breadline/breadline.install.sh"



On Fri, Jan 31, 2020 at 12:21 AM Vasilij Schneidermann 
wrote:

> Hello Matt,
>
> > I've read the docs on linenoise and breadline but I'm not seeing how to
> get
> > a useful editable repl.
> >
> > Any pointers or suggestions would be appreciated.
>
> I've developed breadline.  Its wiki page has an examples section which
> shows how to create a custom REPL for programs an

Re: How to get a useful repl with Chicken 5?

2020-01-31 Thread Vasilij Schneidermann
Hello Matt,

> 4. Code completion works!! Maybe it is a bit much to ask but it'd be useful
> if completion rolled over from internal symbols to files. (*)

Fun fact: The default readline completer uses file names.  If you change
it to something else you no longer get file names.  Since the example
code did that to get Scheme completions, you'd need to extend it to
handle file names.  I don't think I'll reimplement it in Scheme, but it
should nevertheless be a good exercise.

> Thanks Vasilij, this egg is very much appreciated. If no one else is
> reporting problems on Ubuntu 18.04 then likely I've got something messed up
> on my home machine. I'll debug further and report back on what I find.

I'll try to reproduce the issue with Ubuntu 18.04 in a Docker container
or something.

Vasilij


signature.asc
Description: PGP signature


Re: How to get a useful repl with Chicken 5?

2020-01-31 Thread Matt Welland
Updates:

1. breadline installed out of the box, no extra effort required, on SLES11
at work.
2. breadline did exactly what I expected when I added (repl) to the code in
the given csirc example and put it in my program.
3. ^R, history saving and all the other powerful features of readline all
seem to work.
4. Code completion works!! Maybe it is a bit much to ask but it'd be useful
if completion rolled over from internal symbols to files. (*)

Thanks Vasilij, this egg is very much appreciated. If no one else is
reporting problems on Ubuntu 18.04 then likely I've got something messed up
on my home machine. I'll debug further and report back on what I find.

This is what I included in my code to get a repl with line editing, history
etc:

  (case command
((repl)
 (import (chicken load))
 (load-verbose #f)
 (let ()
   (import (chicken format))
   (import (chicken process-context))
   (unless (get-environment-variable "INSIDE_EMACS")
  (import breadline)
  (import breadline-scheme-completion)
  (history-file (format "~a/.csi_history" (get-environment-variable
"HOME")))
  (stifle-history! 1)
  (completer-word-break-characters-set! "\"\'`;|(")
  (completer-set! scheme-completer)
  (basic-quote-characters-set! "\"|")
  (variable-bind! "blink-matching-paren" "on")
  (paren-blink-timeout-set! 20)
  (current-input-port (make-readline-port
 (repl)  ;; added this
)
 . . .

(*) What I mean by rollover is this:
#;> (publis
;; fills out from internal symbols and the publish is filled out. Then I'd
like to enter a filename:
#;> (publish "examples/a
;; if breadline doesn't find an internal symbol "examples/a" then it could
look at the filesystem and list the files that match.

On Fri, Jan 31, 2020 at 4:30 AM Matt Welland  wrote:

> For linenoise I was not able to get saving history to work.
>
> I'm having trouble getting breadline to install on Ubuntu on this old
> laptop. I have libreadline-dev installed but when I do chicken-install
> breadline I get:
>
> matt@matt-HP-EliteBook-6930p:~$ chicken-install breadline
> building breadline
>/home/matt/.cache/chicken-install/breadline/build-breadline -host -D
> compiling-extension -J -s -regenerate-import-libraries -setup-mode -I
> /home/matt/.cache/chicken-install/breadline -C
> -I/home/matt/.cache/chicken-install/breadline -O2 -d1 breadline.scm -o
> /home/matt/.cache/chicken-install/breadline/breadline.so
> Package readline was not found in the pkg-config search path.
> Perhaps you should add the directory containing `readline.pc'
> to the PKG_CONFIG_PATH environment variable
> No package 'readline' found
> Package readline was not found in the pkg-config search path.
> Perhaps you should add the directory containing `readline.pc'
> to the PKG_CONFIG_PATH environment variable
> No package 'readline' found
> Package readline was not found in the pkg-config search path.
> Perhaps you should add the directory containing `readline.pc'
> to the PKG_CONFIG_PATH environment variable
> No package 'readline' found
> Package readline was not found in the pkg-config search path.
> Perhaps you should add the directory containing `readline.pc'
> to the PKG_CONFIG_PATH environment variable
> No package 'readline' found
> /usr/bin/ld: cannot find -lncurses
> collect2: error: ld returned 1 exit status
>
> Error: shell command terminated with non-zero exit status 256: 'gcc'
> '/home/matt/.cache/chicken-install/breadline/breadline.o' -o
> '/home/matt/.cache/chicken-install/breadline/breadline.so' -shared
> -lreadline -lncurses -L/opt/chicken/5.1.0_WW45/lib
> -Wl,-R/opt/chicken/5.1.0_WW45/lib -lchicken -lm -ldl
>/home/matt/.cache/chicken-install/breadline/build-breadline
> -regenerate-import-libraries -setup-mode -static -I
> /home/matt/.cache/chicken-install/breadline -emit-link-file
> /home/matt/.cache/chicken-install/breadline/breadline.link -host -D
> compiling-extension -c -unit breadline -D compiling-static-extension -C
> -I/home/matt/.cache/chicken-install/breadline -O2 -d1 breadline.scm -o
> /home/matt/.cache/chicken-install/breadline/breadline.static.o
> Package readline was not found in the pkg-config search path.
> Perhaps you should add the directory containing `readline.pc'
> to the PKG_CONFIG_PATH environment variable
> No package 'readline' found
> Package readline was not found in the pkg-config search path.
> Perhaps you should add the directory containing `readline.pc'
> to the PKG_CONFIG_PATH environment variable
> No package 'readline' found
> Package readline was not found in the pkg-config search path.
> Perhaps you should add the directory containing `readline.pc'
> to the PKG_CONFIG_PATH environment variable
> No package 'readline' found
> Package readline was not found in the pkg-config search path.
> Perhaps you should add the directory containing `readline.pc'
> to the PKG_CONFIG_PATH environment variable
> No package 'readline' found
>/opt/chicken/5.1.0_WW45/bin/csc -setup-m

Re: How to get a useful repl with Chicken 5?

2020-01-31 Thread Vasilij Schneidermann
Hello again,

> I'll try to reproduce the issue with Ubuntu 18.04 in a Docker container
> or something.

Turns out that for some forsaken reason Ubuntu does neither provide a
`readline.pc` nor uses a reasonable path for headers and libraries.
There are two ways of working around this, one is setting up a
`readline.pc` as described in
, the other one is to
pass the flags shown there via `READLINE_CFLAGS` and `READLINE_LDLIBS`
at installation time:

export READLINE_CFLAGS=-I/usr/include/readline
export READLINE_LDLIBS=-lreadline
chicken-install breadline

Vasilij


signature.asc
Description: PGP signature