There is a neat command-line option in GHCi (i.e., :!).  It allows to
run programs from the interpreter.  For example:

$ ghci
Prelude> :! echo foo
foo

I decided to add a similar option to Guile.  I've attached my attempt.

I wasn't sure which version (branch) to use; I used 2.0.7.  Also, I
didn't bother to really check the code; just tested it a couple of
times.  I'll do it before I send the output of 'git format-patch'.  By
the way, should I assign my copyright prior to that?  (I'm OK with
that, but it may take a while.  And where can I get the form?)

It seems to work:

scheme@(guile-user)> ,run echo foo
foo
scheme@(guile-user)> ,run ls -lh

[...]

scheme@(guile-user)> ,! echo bar baz 42
bar baz 42

Also, I'll try to handle the following cases more gently:

scheme@(guile-user)> ,!
While executing meta-command:
ERROR: Wrong number of arguments to #<procedure 996b440 at 
system/repl/command.scm:931:0 (repl command . args)>

scheme@(guile-user)> ,! foo
While executing meta-command:
ERROR: In procedure system*: No such file or directory

So, what do you think?

--- ./guile-2.0.7/module/system/repl/command.scm	2012-07-06 20:09:10.000000000 +0000
+++ /home/guile-2.0.7/guile-2.0.7/module/system/repl/command.scm	2013-04-11 03:09:02.000000000 +0000
@@ -1,6 +1,7 @@
 ;;; Repl commands
 
 ;; Copyright (C) 2001, 2009, 2010, 2011 Free Software Foundation, Inc.
+;; Copyright (C) 2013 Nikita Karetnikov <nik...@karetnikov.org>
 
 ;; This library is free software; you can redistribute it and/or
 ;; modify it under the terms of the GNU Lesser General Public
@@ -66,7 +67,7 @@
               (traps) (delete del) (disable) (enable)
               (registers regs))
     (inspect  (inspect i) (pretty-print pp))
-    (system   (gc) (statistics stat) (option o)
+    (system   (gc) (statistics stat) (run !) (option o)
               (quit q continue cont))))
 
 (define *show-table*
@@ -927,6 +928,14 @@
     (set! (repl-tm-stats repl) this-tms)
     (set! (repl-gc-stats repl) this-gcs)))
 
+(define-meta-command (run repl command . args)
+  "run
+Run a command."
+  (apply system*
+         (map (lambda (x)
+                (->string x))
+              (cons command args))))
+
 (define (display-stat title flag field1 field2 unit)
   (let ((fmt (format #f "~~20~AA ~~10@A /~~10@A ~~A~~%" (if flag "" "@"))))
     (format #t fmt title field1 field2 unit)))

Attachment: pgpJrXEK7ZxN5.pgp
Description: PGP signature

Reply via email to