2015/08/19
Top-level REPL commands
Another little feature I'm playing for REPL improvements.
S-expression is great to represent tree structure, but it's a bit cumbersome to give simple commands in interactive shell; If the command line is short, the relative verbosity added by open and close parentheses gets in a way. Also in many cases simple commands take string arguments (e.g. to change working directory or to load file) and that require extra double quotes.
I'm not the only one to feel that way. In Allegro CL, if you
type a line begins with :
, it is interpreted as special
toplevel command. Scheme 48 has similar command mode, beginning
with ,
. I guess there are other implementations with
similar features.
So I started adding Scheme 48-ish command syntax. If the first
thing you type in the REPL prompt is a comma, an entire line is
read by read-line
and parsed as a toplevel command,
instead of being read with read
.
You can see current directory or move around:
gosh> ,pwd /home/shiro/src/Gauche/src gosh> ,cd "/home/shiro" gosh> ,cd src/Gauche "/home/shiro/src/Gauche"
You can run apropos:
gosh> ,a cons %tree-map-check-consistency (gauche) acons (gauche) cons (scheme) cons* (gauche) define-constant (gauche) lcons (gauche) lcons* (gauche) gosh> ,a trim srfi-13 string-trim (srfi-13) string-trim-both (srfi-13) string-trim-right (srfi-13)
or describe:
gosh> ,d 31415926 31415926 is an instance of class <integer> (#x1df5e76, ~ 29Mi, 1970-12-30T14:38:46Z as unix-time)
You can omit the argument for describe, in which case it takes the last value of REPL. Whenever you want to see the details of the last evaluation result, just type comma-d:
gosh> (sys-stat "Makefile") #<<sys-stat> 0x14e01e0> gosh> ,d #<<sys-stat> 0x14e01e0> is an instance of class <sys-stat> slots: type : regular perm : 436 mode : 33204 ino : 3295167 dev : 2097 rdev : 0 nlink : 1 uid : 500 gid : 500 size : 4599 atime : 1440031322 mtime : 1440031177 ctime : 1440031177
I'll gradually add more commands. Let me know your ideas.
agumonkey (2015/09/11 06:55:23):
shiro (2015/09/12 01:39:21):