[9fans] Local variables and rc functions
  Home FAQ Contact Sign in
comp.os.plan9 only
 
Advanced search
POPULAR GROUPS

more...

comp.os.plan9 Profile…
 Up
[9fans] Local variables and rc functions         


Author: Micah Stetson
Date: Aug 13, 2008 14:32

Is this a bug?

%% fn foo { echo $bar }
%% bar=baz foo

%%

I would expect to see baz instead of a blank line.

Micah
4 Comments
Re: [9fans] Local variables and rc functions         


Author: roger peppe
Date: Aug 14, 2008 02:30

looks like a bug to me; after all:

%% bar=baz {echo $bar}
baz
%%

i'm somewhat surprised this hasn't been fixed years ago.

On Wed, Aug 13, 2008 at 10:27 PM, Micah Stetson stetsonnet.org> wrote:
> Is this a bug?
>
> %% fn foo { echo $bar }
> %% bar=baz foo
>
> %%
>
> I would expect to see baz instead of a blank line.
>
> Micah
>
>
3 Comments
Re: [9fans] Local variables and rc functions         


Author: kazumi iwane
Date: Aug 14, 2008 04:25

if you want to delay the expansion of an env var until fn invocation,,use eval.

%% fn foo {eval echo $$bar}
Show full article (0.54Kb)
2 Comments
Re: [9fans] Local variables and rc functions         


Author: roger peppe
Date: Aug 14, 2008 05:18

On Thu, Aug 14, 2008 at 12:20 PM, kazumi iwane gmail.com> wrote:
> if you want to delay the expansion of an env var until fn invocation,,use eval.
>
> %% fn foo {eval echo $$bar}

sorry, but that's so, so wrong.

1) $$bar gives the value of the variable
named by the contents of the variable bar,
so that the above, given that $bar contains 'baz'
will echo $baz.

2) $$bar above is evaluated _before_ eval is invoked,
so the line is not very different from {echo $$bar}, except that
if $$bar holds any syntax characters they'll get interpreted by the shell.
it's almost never necessary to use eval with rc.
Show full article (0.96Kb)
1 Comment
Re: [9fans] Local variables and rc functions         


Author: kazumi iwane
Date: Aug 14, 2008 05:53

i apologize for the noise. i should have tested befoqe posting.
rog, thank you for correcting me.

On 8/14/08, roger peppe gmail.com> wrote:
> On Thu, Aug 14, 2008 at 12:20 PM, kazumi iwane gmail.com> wrote:
>> if you want to delay the expansion of an env var until fn invocation,,use...
Show full article (1.18Kb)
no comments

RELATED THREADS
SubjectArticles qty Group
Hypergeometric functions and beta functionssci.math ·
NB question on global/local variables in functionscomp.lang.python ·