* [PATCH] Add ',run' and ',!'
@ 2013-04-11 4:05 Nikita Karetnikov
2013-04-11 5:37 ` Ian Price
0 siblings, 1 reply; 12+ messages in thread
From: Nikita Karetnikov @ 2013-04-11 4:05 UTC (permalink / raw)
To: guile-devel
[-- 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 --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Add ',run' and ',!'
2013-04-11 4:05 [PATCH] Add ',run' and ',!' Nikita Karetnikov
@ 2013-04-11 5:37 ` Ian Price
2013-04-11 23:55 ` Daniel Hartwig
2013-04-12 8:46 ` Ludovic Courtès
0 siblings, 2 replies; 12+ messages in thread
From: Ian Price @ 2013-04-11 5:37 UTC (permalink / raw)
To: Nikita Karetnikov; +Cc: guile-devel
> So, what do you think?
This is the sort of thing that belongs in a .guile rather than in
guile IMO.
--
Ian Price -- shift-reset.com
"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Add ',run' and ',!'
2013-04-11 5:37 ` Ian Price
@ 2013-04-11 23:55 ` Daniel Hartwig
2013-04-12 6:29 ` Nala Ginrut
2014-03-23 19:38 ` Andy Wingo
2013-04-12 8:46 ` Ludovic Courtès
1 sibling, 2 replies; 12+ messages in thread
From: Daniel Hartwig @ 2013-04-11 23:55 UTC (permalink / raw)
To: Ian Price; +Cc: guile-devel
On 11 April 2013 13:37, Ian Price <ianprice90@googlemail.com> wrote:
>
>> So, what do you think?
>
> This is the sort of thing that belongs in a .guile rather than in
> guile IMO.
>
Right, and since you can already do this with more control via the
posix interface, adding this 'shortcut' to the repl adds little in the
way of value.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Add ',run' and ',!'
2013-04-11 23:55 ` Daniel Hartwig
@ 2013-04-12 6:29 ` Nala Ginrut
2013-04-12 7:50 ` Daniel Hartwig
2014-03-23 19:38 ` Andy Wingo
1 sibling, 1 reply; 12+ messages in thread
From: Nala Ginrut @ 2013-04-12 6:29 UTC (permalink / raw)
To: Daniel Hartwig; +Cc: Ian Price, guile-devel
On Fri, 2013-04-12 at 07:55 +0800, Daniel Hartwig wrote:
> On 11 April 2013 13:37, Ian Price <ianprice90@googlemail.com> wrote:
> >
> >> So, what do you think?
> >
> > This is the sort of thing that belongs in a .guile rather than in
> > guile IMO.
> >
>
> Right, and since you can already do this with more control via the
> posix interface, adding this 'shortcut' to the repl adds little in the
> way of value.
>
I think it's worthy making our REPL-command module more extensible, and
we may add customized REPL command.
Just like our new REPL-printer patch, so we may load coloriezed-REPL
without any patch.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Add ',run' and ',!'
2013-04-12 6:29 ` Nala Ginrut
@ 2013-04-12 7:50 ` Daniel Hartwig
2013-04-12 9:37 ` Nala Ginrut
0 siblings, 1 reply; 12+ messages in thread
From: Daniel Hartwig @ 2013-04-12 7:50 UTC (permalink / raw)
To: guile-devel
On 12 April 2013 14:29, Nala Ginrut <nalaginrut@gmail.com> wrote:
> On Fri, 2013-04-12 at 07:55 +0800, Daniel Hartwig wrote:
>> On 11 April 2013 13:37, Ian Price <ianprice90@googlemail.com> wrote:
>> >
>> >> So, what do you think?
>> >
>> > This is the sort of thing that belongs in a .guile rather than in
>> > guile IMO.
>> >
>>
>> Right, and since you can already do this with more control via the
>> posix interface, adding this 'shortcut' to the repl adds little in the
>> way of value.
>>
>
> I think it's worthy making our REPL-command module more extensible, and
> we may add customized REPL command.
That is what ‘define-meta-command’ is for, though be sure to specify a
category (here ‘wigs’):
scheme@(guile-user)> (use-modules (system repl command))
scheme@(guile-user)> (define-meta-command ((foo wigs) repl . args)
"does a lot"
(display "foo")
(newline))
scheme@(guile-user)> ,foo
foo
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Add ',run' and ',!'
2013-04-11 5:37 ` Ian Price
2013-04-11 23:55 ` Daniel Hartwig
@ 2013-04-12 8:46 ` Ludovic Courtès
2013-04-12 23:52 ` Nikita Karetnikov
1 sibling, 1 reply; 12+ messages in thread
From: Ludovic Courtès @ 2013-04-12 8:46 UTC (permalink / raw)
To: Nikita Karetnikov; +Cc: Ian Price, guile-devel
Ian Price <ianprice90@googlemail.com> skribis:
>> So, what do you think?
>
> This is the sort of thing that belongs in a .guile rather than in
> guile IMO.
+1.
(Besides, note that copyright for code contributed to Guile should be
held by the FSF.)
Ludo’.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Add ',run' and ',!'
2013-04-12 7:50 ` Daniel Hartwig
@ 2013-04-12 9:37 ` Nala Ginrut
2013-04-12 14:38 ` Ian Price
0 siblings, 1 reply; 12+ messages in thread
From: Nala Ginrut @ 2013-04-12 9:37 UTC (permalink / raw)
To: Daniel Hartwig; +Cc: guile-devel
On Fri, 2013-04-12 at 15:50 +0800, Daniel Hartwig wrote:
> On 12 April 2013 14:29, Nala Ginrut <nalaginrut@gmail.com> wrote:
> > On Fri, 2013-04-12 at 07:55 +0800, Daniel Hartwig wrote:
> >> On 11 April 2013 13:37, Ian Price <ianprice90@googlemail.com> wrote:
> >> >
> >> >> So, what do you think?
> >> >
> >> > This is the sort of thing that belongs in a .guile rather than in
> >> > guile IMO.
> >> >
> >>
> >> Right, and since you can already do this with more control via the
> >> posix interface, adding this 'shortcut' to the repl adds little in the
> >> way of value.
> >>
> >
> > I think it's worthy making our REPL-command module more extensible, and
> > we may add customized REPL command.
>
> That is what ‘define-meta-command’ is for, though be sure to specify a
> category (here ‘wigs’):
>
> scheme@(guile-user)> (use-modules (system repl command))
> scheme@(guile-user)> (define-meta-command ((foo wigs) repl . args)
> "does a lot"
> (display "foo")
> (newline))
> scheme@(guile-user)> ,foo
> foo
>
Ah~very nice~
So many cool things should be documented...
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Add ',run' and ',!'
2013-04-12 9:37 ` Nala Ginrut
@ 2013-04-12 14:38 ` Ian Price
2013-04-12 23:45 ` Nikita Karetnikov
0 siblings, 1 reply; 12+ messages in thread
From: Ian Price @ 2013-04-12 14:38 UTC (permalink / raw)
To: Nala Ginrut; +Cc: guile-devel
Nala Ginrut <nalaginrut@gmail.com> writes:
> Ah~very nice~
> So many cool things should be documented...
Yeah, I've been meaning to do this. I'll try and get a patch for later
today/tomorrow.
--
Ian Price -- shift-reset.com
"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Add ',run' and ',!'
2013-04-12 14:38 ` Ian Price
@ 2013-04-12 23:45 ` Nikita Karetnikov
0 siblings, 0 replies; 12+ messages in thread
From: Nikita Karetnikov @ 2013-04-12 23:45 UTC (permalink / raw)
To: Ian Price; +Cc: guile-devel
[-- Attachment #1: Type: text/plain, Size: 194 bytes --]
> Yeah, I've been meaning to do this. I'll try and get a patch for later
> today/tomorrow.
Great.
Could you also add more examples to the .guile-related section? What do
you have in .guile?
[-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Add ',run' and ',!'
2013-04-12 8:46 ` Ludovic Courtès
@ 2013-04-12 23:52 ` Nikita Karetnikov
0 siblings, 0 replies; 12+ messages in thread
From: Nikita Karetnikov @ 2013-04-12 23:52 UTC (permalink / raw)
To: Ludovic Courtès; +Cc: Ian Price, guile-devel
[-- Attachment #1: Type: text/plain, Size: 129 bytes --]
>> This is the sort of thing that belongs in a .guile rather than in
>> guile IMO.
> +1.
OK. I hope that it'll be documented.
[-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Add ',run' and ',!'
2013-04-11 23:55 ` Daniel Hartwig
2013-04-12 6:29 ` Nala Ginrut
@ 2014-03-23 19:38 ` Andy Wingo
2014-03-23 20:03 ` Doug Evans
1 sibling, 1 reply; 12+ messages in thread
From: Andy Wingo @ 2014-03-23 19:38 UTC (permalink / raw)
To: Daniel Hartwig; +Cc: Ian Price, guile-devel
Hi,
Following up after a loooong time --
On Fri 12 Apr 2013 01:55, Daniel Hartwig <mandyke@gmail.com> writes:
> On 11 April 2013 13:37, Ian Price <ianprice90@googlemail.com> wrote:
>>
>>> So, what do you think [about ,run and ,!]?
>>
>> This is the sort of thing that belongs in a .guile rather than in
>> guile IMO.
>>
>
> Right, and since you can already do this with more control via the
> posix interface, adding this 'shortcut' to the repl adds little in the
> way of value.
I'm not sure I agree. Anything a REPL command can do can also be done
programmatically, so that's not really an argument against REPL
commands. OTOH people find that the ability to shell out is useful --
almost all language shells have such a thing. I think such a feature
could have a place in Guile proper.
Andy
--
http://wingolog.org/
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Add ',run' and ',!'
2014-03-23 19:38 ` Andy Wingo
@ 2014-03-23 20:03 ` Doug Evans
0 siblings, 0 replies; 12+ messages in thread
From: Doug Evans @ 2014-03-23 20:03 UTC (permalink / raw)
To: Andy Wingo; +Cc: Ian Price, guile-devel
On Sun, Mar 23, 2014 at 12:38 PM, Andy Wingo <wingo@pobox.com> wrote:
> Hi,
>
> Following up after a loooong time --
>
> On Fri 12 Apr 2013 01:55, Daniel Hartwig <mandyke@gmail.com> writes:
>
>> On 11 April 2013 13:37, Ian Price <ianprice90@googlemail.com> wrote:
>>>
>>>> So, what do you think [about ,run and ,!]?
>>>
>>> This is the sort of thing that belongs in a .guile rather than in
>>> guile IMO.
>>>
>>
>> Right, and since you can already do this with more control via the
>> posix interface, adding this 'shortcut' to the repl adds little in the
>> way of value.
>
> I'm not sure I agree. Anything a REPL command can do can also be done
> programmatically, so that's not really an argument against REPL
> commands. OTOH people find that the ability to shell out is useful --
> almost all language shells have such a thing. I think such a feature
> could have a place in Guile proper.
fwiw, I use ! in gdb all the time.
I would find ,! in guile's repl very useful myself.
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2014-03-23 20:03 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-11 4:05 [PATCH] Add ',run' and ',!' Nikita Karetnikov
2013-04-11 5:37 ` 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
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).