Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

intersting side-effect to dynamic word usage...

 [1/12] from: media:quazart at: 15-Nov-2001 9:57


Hello world, What I am about to point out might be common knowledge to some of you but in the hopes that this will be usefull to someone, I explain it anyways... Basically, there is a side-effect to using 'to-word and more specifically 'to-set-word... here is a little piece of code which illustrates this. I have added some comments in-line in the code so that I can explain just what happens as the program executes. I have used Romano's excelent anamonitor.r script to give visual feedback of exactly what happens... to run the code below, download his script (if its not already in your favorite downloads) and just change the path so that it can be loaded. Otherwise, just read the comments in the code, as these explain what happens if you do not wish to run the example. ------------ code follows ----------------- rebol [] ;----------- LOAD Romano's object/block browser do load %/your/path/to/romanos/anamonitor.r aaa-block: [] monitor system/words dynamic-word: ask "WHAT IS NEW WORD TO ADD? :" ;----------------- ; let's say we answered "aaa", we now append this string to our word-block ; append aaa-block to-set-word dynamic-word ;---------- AT THIS POINT IN EXECUTION, ; something funky happens... ; the set-word exists within the block which is now set as [aaa:] ; this is expected... ; ; BUT! ; ; a word is ALSO set inside the system/words block and is set to ; aaa ; ; I just thought I'd note this as it might interest some of you ; ; check it out: monitor system/words ; ; here I just set the value (WITHOUT USING the word's name in the code) ; set in system/words to-word form first aaa-block "MAMA!" print to-word form first aaa-block monitor system/words ask "" Anyways, this is just a quick trick I found out... the above also seems to stand if you use the to-word function .... which also seems to instantly add the word in system/words, even if you're inserting it in a block directly. -MAx

 [2/12] from: brett:codeconscious at: 16-Nov-2001 10:25


Hi Max,
>.... which also seems to instantly > add the word in system/words, even if you're inserting it in a block > directly.
As far as I know, system/words is updated with every word defined in Rebol by whatever means they are created. Larry Palmiter has pointed out that there is a finite limit to the number of words that are created in the order of a few thousand I believe. While this sounds limiting, in practise I've never hit this limit with my programs. Also some clever people have shown how one can determine if a word in system/words is defined globally or not. Based on this there are a couple of tools floating around that can show what global words you have created by mistake perhaps. To see an example try my Rebsite "Code. C." and click on "Library List". A list of programs will appear. If you left click on a program name you will see the source code. If you right click on a name the script will be run inside of a function that determines what new global words are set by that script. The results are displayed as a simple list. Cheers, Brett.

 [3/12] from: ammonjohnson:y:ahoo at: 15-Nov-2001 17:25


What you are experiences here is REBOL "cataloging" all set-words which are in a script wether or not they are set at the Global Level. ;-) To see what I mean try this: a: context [ a-word: "text" ] you will find 'a-word in System/Words. HTH Ammon

 [4/12] from: rotenca:telvia:it at: 16-Nov-2001 3:31


Hi, Brett
> > add the word in system/words, even if you're inserting it in a block > > directly. > > As far as I know, system/words is updated with every word defined in Rebol > by whatever means they are created.
You can create words and use them normally, without adding them to the Global Context. Try:
>> fx: first to-block "foo"
== foo
>> print in context to-block "foo: 3" fx
foo
>> use to-block "foo" bind to-block "foo: 7 print foo" 'system
7
>> to-path "a/foo"
== a/foo
>> do func to-block "foo" to-block "foo" 10
== 10
>> print in system/words fx
none You must not use load or the default loader (of do and console), to-refinement or to-xxx-word. Becomes a global word also the first element of a path, not the others. If you must load a long data file with many new words, i think could be better to use to-block and not load. --- Ciao Romano

 [5/12] from: brett::codeconscious::com at: 16-Nov-2001 18:13


Thanks for that Romano. One learns something every day :) Brett.

 [6/12] from: ingo:2b1 at: 16-Nov-2001 13:06


Hi Romano, Once upon a time Romano Paolo Tenca spoketh thus:
> Hi, Brett > > > add the word in system/words, even if you're inserting it in a block
<<quoted lines omitted: 6>>
> >> fx: first to-block "foo" > == foo
<..>
> >> print in system/words fx > none
<..> I tried it ...
>> query/clear system/words
== [end! unset! error! datatype! context! native! action! routine! op! function! object! struct! library! port! any-type! any-word!...
>> query system/words
== none
>> fx: first to-block "foo"
== foo
>> query system/words
== [fx]
>> probe system/words
== [ <... shortened a little ...> link-init-done: unset link-sweep-app: unset fx: 'foo ]
>>
Seems to me, it _is_ added to system/words, though I don't understand why it returns 'none ... kind regards, Ingo

 [7/12] from: rotenca:telvia:it at: 16-Nov-2001 14:57


Hi, Hingo It is added 'fx not 'foo. I defined fx as a pointer to 'foo. 'foo is added to the Global Context (GC) as the value of 'fx, but it is not a word defined in the GC.
> >> fx: first to-block "foo" > == foo > >> query system/words > == [fx]
The only new global word here is 'fx If you first load the same string:
>> fx: first to-block load "foo"
== foo You'll find 2 new words:
>> query/clear system/words
== [fx foo]
> >> probe system/words > == [ <... shortened a little ...> > link-init-done: unset > link-sweep-app: unset > fx: 'foo > ]
'foo is the value of 'fx, not a field of the GC. --- Ciao Romano

 [8/12] from: media:quazart at: 16-Nov-2001 9:49


hi Romano,
> 'foo is the value of 'fx, not a field of the GC.
ok, but then What is it used for!? The example I submitted also did that, in the sense that I'm using a word in a block.. The monitor explicitely shows that the word isn't added until the to-set-word call... is it possible to then create objects on-the-fly without their attributes ending up in the GC as set (or unset) words in system/words ? And then, is it possible for th GC to remain clean even if we access these attributes, later even by using like: my value: get in myObject first ['attribute] ??? TIA! ciao! -Maxim

 [9/12] from: greggirwin:mindspring at: 16-Nov-2001 11:45


Hi Romano, et al I was thinking that all this was sinking in pretty well for me...then I lost track in my mind of the following basic question: Is it the GC or system/words that is limited to roughly 4K entries? If the former, we can use contexts to overcome the limit to a great extent, but if it's the latter, we really want to be careful about how we do things, per this thread. Is that correct? --Gregg

 [10/12] from: rotenca:telvia:it at: 16-Nov-2001 20:34


Hi, Media
> > 'foo is the value of 'fx, not a field of the GC. > > ok, but then What is it used for!?
Only as a shortcut to 'foo.
> The example I submitted also did that, in the sense that I'm using a word > in a block.. The monitor explicitely shows that the word isn't added until > the to-set-word call...
Yes. Or Load or To-xxx-path (first token) or To-xxx-word, or Do with a string/file/url, because it makes a inner call to Load.
> is it possible to then create objects on-the-fly without their attributes > ending up in the GC as set (or unset) words in system/words ?
Yes, it already was in my example, here it is another one: myObject: context to-block "attribute: 3"
> And then, is it possible for th GC to remain clean even if we access these > attributes, later even by using like: > > my value: get in myObject first ['attribute]
When the system Load this expression in the console or in a script, it adds 'attribute at the GC, so you do not reach your goal. Here it is the right version: myvalue: get in myObject first to-block "attribute" or you could do, to mask myvalue too: code: bind to-block { use [myvalue][ myvalue: get in myObject 'attribute print myvalue ] } 'system do code Bind doesn't add any word to the GC. So 'myvalue and 'attribute in this case are not added to the GC. It is possible to write functions which do not change GC, like: use-mask: func [vars [string!] code [string!]] [ do use to-block vars bind to-block code 'system ] use-mask "my" "my: 3 print my" func-mask: func [spec [string!] body [string!]] [ func to-block spec bind to-block body 'system ] x: func-mask "my" "print my" x 3 I've uploaded some example code to my rebsite (Romano).
> ciao! > > -Maxim
ciao, ciao Romano

 [11/12] from: g:santilli:tiscalinet:it at: 17-Nov-2001 14:30


Hello Media! On 15-Nov-01, you wrote: M> Basically, there is a side-effect to using 'to-word and more M> specifically 'to-set-word... Any word loaded by REBOL (via LOAD, DO, TO-WORD etc.) is added to system/words. This is the reason why the global context is extensible why any other context is not. Regards, Gabriele. -- Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/

 [12/12] from: ammonjohnson:yah:oo at: 17-Nov-2001 13:40


Yes, roughly 4K entries. Contexts will not save you from the words being in the "GC" (we need to be careful how we call that the "GC" REBOL refers to Garbage Collection as GC) There have been ways mentioned in this thread of how to avoid words being in the GN (Global Namespace), but they rely on you knowing just how each word is called, & only calling it from your specially designed functions. (ie. if someone typed the path to your word(s) in the console, your attempt to keep them from the GN has failed.) HTH Ammon

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted