9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] environment + functions
@ 2008-10-07 18:31 Rudolf Sykora
  2008-10-07 18:33 ` erik quanstrom
  2008-10-07 18:52 ` andrey mirtchovski
  0 siblings, 2 replies; 10+ messages in thread
From: Rudolf Sykora @ 2008-10-07 18:31 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 320 bytes --]

Hello,

why after creating a function with

fn my_func_name { something }

and removing this function with

fn my_func_name

a file (though of zero size) exists in /env?

(If I create a lot of functions and then want them be removed, I find a lot
of for-me-uninteresting files in /env...)

Thanks,
Ruda

[-- Attachment #2: Type: text/html, Size: 380 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [9fans] environment + functions
  2008-10-07 18:31 [9fans] environment + functions Rudolf Sykora
@ 2008-10-07 18:33 ` erik quanstrom
  2008-10-07 18:52 ` andrey mirtchovski
  1 sibling, 0 replies; 10+ messages in thread
From: erik quanstrom @ 2008-10-07 18:33 UTC (permalink / raw)
  To: 9fans

> why after creating a function with
>
> fn my_func_name { something }
>
> and removing this function with
>
> fn my_func_name
>
> a file (though of zero size) exists in /env?
>
> (If I create a lot of functions and then want them be removed, I find a lot
> of for-me-uninteresting files in /env...)

good question.  there are several interesting things about
how rc deals with the environment.

- erik




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [9fans] environment + functions
  2008-10-07 18:31 [9fans] environment + functions Rudolf Sykora
  2008-10-07 18:33 ` erik quanstrom
@ 2008-10-07 18:52 ` andrey mirtchovski
  2008-10-08 10:58   ` Rudolf Sykora
  1 sibling, 1 reply; 10+ messages in thread
From: andrey mirtchovski @ 2008-10-07 18:52 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

this is a consequence of how environment variables are treated by the
shell and what appears in /env. there is a disconnect between the file
server and the shell (in essence the shell doesn't consult /env upon
each reference. for example if you simply create a file in /env your
current shell won't pick it up as a variable but if you start a new
one it will be there:

9grid% echo $test

9grid% echo -n 'thisisatest' > /env/test
9grid% echo $test

9grid% rc
9grid% echo $test
thisisatest
9grid%

the same way if you just delete a file from /env the shell will not
pick up the deletion:

9grid% echo $test
thisisatest
9grid% rm /env/test
9grid% echo $test
thisisatest
9grid% rc
9grid% echo $test

9grid%

it's done this way, i believe, to ensure that two rc shells running in
the same namespaces do not step all over each others' environments. if
you simply run 'rfork e' before you experiment with all those
functions you won't see the empty files anywhere.

last note: once you've deleted the function with the 'fn' builtin
you're free to remove the corresponding file in /env: it won't matter
anymore. i'm sure rc can be changed to delete the file.


On Tue, Oct 7, 2008 at 12:31 PM, Rudolf Sykora <rudolf.sykora@gmail.com> wrote:
> Hello,
>
> why after creating a function with
>
> fn my_func_name { something }
>
> and removing this function with
>
> fn my_func_name
>
> a file (though of zero size) exists in /env?
>
> (If I create a lot of functions and then want them be removed, I find a lot
> of for-me-uninteresting files in /env...)
>
> Thanks,
> Ruda
>
>



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [9fans] environment + functions
  2008-10-07 18:52 ` andrey mirtchovski
@ 2008-10-08 10:58   ` Rudolf Sykora
  2008-10-08 18:46     ` Pietro Gagliardi
  0 siblings, 1 reply; 10+ messages in thread
From: Rudolf Sykora @ 2008-10-08 10:58 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 1212 bytes --]

>
> it's done this way, i believe, to ensure that two rc shells running in
> the same namespaces do not step all over each others' environments. if
> you simply run 'rfork e' before you experiment with all those
> functions you won't see the empty files anywhere.


Sorry, but I don't understand... Could you give me some example?


> last note: once you've deleted the function with the 'fn' builtin
> you're free to remove the corresponding file in /env: it won't matter
> anymore. i'm sure rc can be changed to delete the file.
>

So, if I continuously want to add and remove functions within one shell
(running hypothetically forever), do I have to 'manually' delete those empty
left-behind files? --- that is, not only use
fn name_that_I _don't_need
but also
rm /env/'fn#name_that_I _don't_need' ?

(I was playing with this to have a prompt that reflects the last part of my
current directory. Following the example of setting fn term% { $*} I,
whenever I change a directory, define a similar function with an appropriate
name. When I change the directory again I do the same for the new one, but
also want to get rid of the old one... -- actually in the opposite order.)

Ruda

[-- Attachment #2: Type: text/html, Size: 1674 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [9fans] environment + functions
  2008-10-08 10:58   ` Rudolf Sykora
@ 2008-10-08 18:46     ` Pietro Gagliardi
  2008-10-08 18:52       ` Rudolf Sykora
  0 siblings, 1 reply; 10+ messages in thread
From: Pietro Gagliardi @ 2008-10-08 18:46 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs


On Oct 8, 2008, at 6:58 AM, Rudolf Sykora wrote:

> So, if I continuously want to add and remove functions within one
> shell (running hypothetically forever), do I have to 'manually'
> delete those empty left-behind files? --- that is, not only use
> fn name_that_I _don't_need
> but also
> rm /env/'fn#name_that_I _don't_need' ?

No.




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [9fans] environment + functions
  2008-10-08 18:46     ` Pietro Gagliardi
@ 2008-10-08 18:52       ` Rudolf Sykora
  2008-10-08 19:12         ` erik quanstrom
  2008-10-08 19:16         ` Pietro Gagliardi
  0 siblings, 2 replies; 10+ messages in thread
From: Rudolf Sykora @ 2008-10-08 18:52 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 407 bytes --]

 So, if I continuously want to add and remove functions within one shell
>> (running hypothetically forever), do I have to 'manually' delete those empty
>> left-behind files? --- that is, not only use
>> fn name_that_I _don't_need
>> but also
>> rm /env/'fn#name_that_I _don't_need' ?
>>
>
> No.
>

Well... that's an answer, but not very constructive indeed. When do those
files dissapear?
R.

[-- Attachment #2: Type: text/html, Size: 816 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [9fans] environment + functions
  2008-10-08 18:52       ` Rudolf Sykora
@ 2008-10-08 19:12         ` erik quanstrom
  2008-10-08 19:16         ` Pietro Gagliardi
  1 sibling, 0 replies; 10+ messages in thread
From: erik quanstrom @ 2008-10-08 19:12 UTC (permalink / raw)
  To: rudolf.sykora, 9fans

>
> Well... that's an answer, but not very constructive indeed. When do those
> files dissapear?

they don't.  but it shouldn't be a problem.
there's no explicit limit.  why don't you
sidestep the problem by using a space between
the fixed part and the path?

- erik



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [9fans] environment + functions
  2008-10-08 18:52       ` Rudolf Sykora
  2008-10-08 19:12         ` erik quanstrom
@ 2008-10-08 19:16         ` Pietro Gagliardi
  2008-10-08 19:25           ` Rudolf Sykora
  1 sibling, 1 reply; 10+ messages in thread
From: Pietro Gagliardi @ 2008-10-08 19:16 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Oct 8, 2008, at 2:52 PM, Rudolf Sykora wrote:

>
>
> So, if I continuously want to add and remove functions within one
> shell (running hypothetically forever), do I have to 'manually'
> delete those empty left-behind files? --- that is, not only use
> fn name_that_I _don't_need
> but also
> rm /env/'fn#name_that_I _don't_need' ?
>
> No.
>
> Well... that's an answer, but not very constructive indeed. When do
> those files dissapear?
> R.

When the namespace disappears.

You can ignore the file even being there. There is a difference
between the file and how the program uses them. If the program (rc)
doesn't have a function given a name but /env does, it makes no
difference. rc will overwrite the file when you redefine the function.




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [9fans] environment + functions
  2008-10-08 19:16         ` Pietro Gagliardi
@ 2008-10-08 19:25           ` Rudolf Sykora
  0 siblings, 0 replies; 10+ messages in thread
From: Rudolf Sykora @ 2008-10-08 19:25 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 1211 bytes --]

2008/10/8 Pietro Gagliardi <pietro10@mac.com>

> On Oct 8, 2008, at 2:52 PM, Rudolf Sykora wrote:
>
>
>>
>> So, if I continuously want to add and remove functions within one shell
>> (running hypothetically forever), do I have to 'manually' delete those empty
>> left-behind files? --- that is, not only use
>> fn name_that_I _don't_need
>> but also
>> rm /env/'fn#name_that_I _don't_need' ?
>>
>> No.
>>
>> Well... that's an answer, but not very constructive indeed. When do those
>> files dissapear?
>> R.
>>
>
> When the namespace disappears.
>
> You can ignore the file even being there. There is a difference between the
> file and how the program uses them. If the program (rc) doesn't have a
> function given a name but /env does, it makes no difference. rc will
> overwrite the file when you redefine the function.
>

Well, when it disappears, sure. All what you say is understandable and I
know it. But as I explicitly noted, this namespace presumably never
disappears and the number of files increases. And having trillion useless
files is for no good. Moreover, as I tried to say, I don't see the reason
for that they stay there. See my about 4 hours old mail.
Ruda

[-- Attachment #2: Type: text/html, Size: 1738 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [9fans] environment + functions
@ 2008-10-08 11:35 erik quanstrom
  0 siblings, 0 replies; 10+ messages in thread
From: erik quanstrom @ 2008-10-08 11:35 UTC (permalink / raw)
  To: rudolf.sykora, 9fans

> > it's done this way, i believe, to ensure that two rc shells running in
> > the same namespaces do not step all over each others' environments. if
> > you simply run 'rfork e' before you experiment with all those
> > functions you won't see the empty files anywhere.
>
> Sorry, but I don't understand... Could you give me some example?

; i=0
; @{i=1; sleep 2; echo $i} & @{i=2; sleep 1; echo $i} ; wait
2
1
; ; cat /env/i
0;

> (I was playing with this to have a prompt that reflects the last part of my
> current directory. Following the example of setting fn term% { $*} I,
> whenever I change a directory, define a similar function with an appropriate
> name. When I change the directory again I do the same for the new one, but
> also want to get rid of the old one... -- actually in the opposite order.)

sounds complicated.  why do you need to define a function for each new
directory?  the prompt trick is sneaky.  it relies on the space.  why not
just move the space and make the thing that required a new function
an argument to a fixed function?

fn $sysname: {
}
fn cd{
	builtin cd $*
	awd
	prompt=($sysname:' '`{basename `{pwd}}^'; ' '')
}

or you can go minimilst bourne and have

fn : {
}
fn cd{
	bultin cd $*
	awd
	prompt=(': '`{basename `{pwd}}^'; ' '')
}

- erik



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2008-10-08 19:25 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-07 18:31 [9fans] environment + functions Rudolf Sykora
2008-10-07 18:33 ` erik quanstrom
2008-10-07 18:52 ` andrey mirtchovski
2008-10-08 10:58   ` Rudolf Sykora
2008-10-08 18:46     ` Pietro Gagliardi
2008-10-08 18:52       ` Rudolf Sykora
2008-10-08 19:12         ` erik quanstrom
2008-10-08 19:16         ` Pietro Gagliardi
2008-10-08 19:25           ` Rudolf Sykora
2008-10-08 11:35 erik quanstrom

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).