9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: "kazumi iwane" <kiwane@gmail.com>
To: "Fans of the OS Plan 9 from Bell Labs" <9fans@9fans.net>
Subject: Re: [9fans] Local variables and rc functions
Date: Thu, 14 Aug 2008 21:47:59 +0900	[thread overview]
Message-ID: <467ac3900808140547s20ea866ch97a622ac3e41f21c@mail.gmail.com> (raw)
In-Reply-To: <df49a7370808140514ie8bd3aet9c75ee6af579f3fb@mail.gmail.com>

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

On 8/14/08, roger peppe <rogpeppe@gmail.com> wrote:
> On Thu, Aug 14, 2008 at 12:20 PM, kazumi iwane <kiwane@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.
>
> 3) expansion of env. vars *is* delayed until fn invocation.
> e.g.
> % fn foo {echo $bar}
> % bar = baz
> % foo
> baz
> %
>
> it just seems as if the local variable assignment isn't propagated
> into the fn context. i don't have time to look into it now (i really
> shouldn't be spending time writing this email, but i couldn't resist the
> bait).
>
>   rog.
>
>



  reply	other threads:[~2008-08-14 12:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-13 21:27 Micah Stetson
2008-08-14  9:25 ` roger peppe
2008-08-14 11:20   ` kazumi iwane
2008-08-14 12:14     ` roger peppe
2008-08-14 12:47       ` kazumi iwane [this message]
2008-08-14 14:32 Russ Cox
2008-08-14 18:10 ` Micah Stetson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=467ac3900808140547s20ea866ch97a622ac3e41f21c@mail.gmail.com \
    --to=kiwane@gmail.com \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).