unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Nikita Karetnikov <nikita@karetnikov.org>
To: guile-devel@gnu.org
Subject: [PATCH] Add ',run' and ',!'
Date: Thu, 11 Apr 2013 08:05:20 +0400	[thread overview]
Message-ID: <87fvyx4sqn.fsf@karetnikov.org> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 1077 bytes --]

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?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: run.diff --]
[-- Type: text/x-diff, Size: 1325 bytes --]

--- ./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 <nikita@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 #2: Type: application/pgp-signature, Size: 835 bytes --]

             reply	other threads:[~2013-04-11  4:05 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-11  4:05 Nikita Karetnikov [this message]
2013-04-11  5:37 ` [PATCH] Add ',run' and ',!' Ian Price
2013-04-11 23:55   ` Daniel Hartwig
2013-04-12  6:29     ` Nala Ginrut
2013-04-12  7:50       ` Daniel Hartwig
2013-04-12  9:37         ` Nala Ginrut
2013-04-12 14:38           ` Ian Price
2013-04-12 23:45             ` Nikita Karetnikov
2014-03-23 19:38     ` Andy Wingo
2014-03-23 20:03       ` Doug Evans
2013-04-12  8:46   ` Ludovic Courtès
2013-04-12 23:52     ` Nikita Karetnikov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87fvyx4sqn.fsf@karetnikov.org \
    --to=nikita@karetnikov.org \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).