This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: Shell-style programming in Kawa
- From: Per Bothner <per at bothner dot com>
- To: Jamison Hope <jrh at theptrgroup dot com>, "kawa at sourceware dot org list" <kawa at sourceware dot org>
- Date: Sun, 26 Jan 2014 15:25:19 -0800
- Subject: Re: Shell-style programming in Kawa
- Authentication-results: sourceware.org; auth=none
- References: <52C4B518 dot 5080000 at bothner dot com> <A72FB562-9459-4C69-B346-A6C94DBD22C4 at theptrgroup dot com> <52E3772D dot 50804 at bothner dot com> <4A37A2F8-76B0-421D-AFCB-62AA1EE78468 at theptrgroup dot com>
On 01/25/2014 11:46 PM, Jamison Hope wrote:
Is there a way to make this do what I intend?
&`{ls &`{pwd}/..}
There are two issues:
- The &`{pwd} part and the "/.." part are tokenized separately,
i.e. it becomes something like (run-process ["ls" &`{pwd} "/.."]).
- The expansion of &`{pwd} has an embedded newline at the end, so it's
not enough to just concatenate the two strings.
There is code to handle this - search for "Skip final '\n'" in the method
tokenize in RunProcess. However, the logic test is never executed -
instead the previous test matches.
There is similar logic in the handleMarks method, used when shell is #t.
Search for the same comment string. That also appears to be broken,
judging by the output from:
&sh{echo &`{pwd}/..}
However, we may want to re-think how this is handled. The first
question is:
Should:
&`{cmd1 ...&`{cmd2}...}
by different from:
(let ((tmp &`{cmd2})) &`{cmd1 ...&[tmp]...})
or (equivalently):
&`{cmd1 ...&[&`{cmd2}]...}
Relatedly, should we strip the final '\n' from interpolated
strings in general:
(let ((tmp "foo\n")) &`{cmd1 &[foo]...})
In traditional command shells, a final '\n' is only
stripped in specific command substitution, but not in variable
substitution, To mostly closely match that, we should strip
the final '\n' in:
&`{cmd1 ...&`{cmd2}...}
but not remove a final '\n' in:
(let ((tmp &`{cmd2})) &`{cmd1 ...&[tmp]...})
or:
&`{cmd1 ...&[&`{cmd2}]...}
or:
(let ((tmp "foo\n")) &`{cmd1 &[foo]...})
However, this seems rather non-Scheme-y to me.
Instead, I think we should treat:
&`{cmd1 ....&`{cmd}...}
as equivalent to:
&`{cmd1 ....&[&`{cmd}]...}
and in general:
&`{cmd ...&[expr]...}
by implicitly (and always) removing the final '\n' from expr.
(Assuming expr is not an array of strings, which is handled differently.)
An alternative to to change the behavior of converting a Process
to a string to do the '\n'-stripping there instead. I.e. have:
(define str::string &`{echo foo bar})
bind "foo bar" to str. rather than "foo bar\n".
The latter (change the string conversion) may be a more useful
behavior; I have to mull it some more. Reactions?
--
--Per Bothner
per@bothner.com http://per.bothner.com/