[9fans] environment + functions - Plan9

This is a discussion on [9fans] environment + functions - Plan9 ; 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 ...

+ Reply to Thread
Results 1 to 8 of 8

Thread: [9fans] environment + functions

  1. [9fans] environment + functions

    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


  2. Re: [9fans] environment + functions

    > 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



  3. Re: [9fans] environment + functions

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



  4. Re: [9fans] environment + functions

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


  5. Re: [9fans] environment + functions


    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.



  6. Re: [9fans] environment + functions

    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.


  7. Re: [9fans] environment + functions

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


  8. Re: [9fans] environment + functions

    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.



+ Reply to Thread