This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Shell-style programming in Kawa


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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]