|
From: Ethan M. <merritt@u.washington.edu> - 2004-10-24 22:37:41
|
On Saturday 16 October 2004 03:59 am, Juergen Wieferink wrote:
> Petr Mikulik wrote:
> > I though that instead of using
> > a=`runme`
> > there would be an alternative with macro expansion:
> > a=command('runme')
>
> Yes, yes, I'd love that. The variable "a" contains a string
> afterwards, doesn't it?
I did figure out how to implement a gnuplot function
<string-value> = command(<string-expression>)
but I have serious reservations about it.
(1) it leaks memory (probably fixable, but so far I haven't
figured out how)
(2) it makes me really uneasy that you could trigger evaluation
of this function from, say, inside a plot statement:
plot <foo> 1:using (command("something expensive"))
This could, to say the least, consume system resources.
So instead I offer the following alternative proposal.
I have updated the patchset on SourceForge to include the
following variant syntax
@"stringvar" evaluates to "contents of stringvar"
That is, it evaluates the stringvar and places the value in
double-quotes.
For string constants this is a complicated no-op.
E.g.
a = "string constant blah blah"
b = a
c = @"a"
a, b, and c now contain identically the same string.
But when back-tics are involved it becomes more interesting.
> I need something like
>
> gawkcall = sprintf("gawk -f getname %i %s", this_index, filename)
> name = execute(gawkcall)
With the new syntax, you would do this as follows:
gawkcall = sprintf( '` gawk -f getname %i %s `', ...)
show var
gawkcall = ` gawk -f getname ... `
name = @"gawkcall"
Note that the sprintf call uses single-quote + back-tic to delimit
the command string.
name becomes a string variable containing the output from
executing the shell command in gawkcall.
What do you think? Is this sufficient, or is there still a need for
an actual function command("foo")?
|