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

'use question

 [1/16] from: maarten:koopmans:surfnet:nl at: 30-Oct-2002 11:31


Hi, COnsider the following code: f: use [ b ][b: 10 does [ b + 1 ]] How can I access b later on directly? Or: How can I access local variables of a use block later on? --Maarten

 [2/16] from: gscottjones:mchsi at: 30-Oct-2002 5:33


From: "Maarten Koopmans"
> COnsider the following code: > > f: use [ b ][b: 10 does [ b + 1 ]] > > How can I access b later on directly? > Or: How can I access local variables of a use block later on?
Hi, Maarten, Neat problem!! :-) Here is one way: ;original f: use [ b ][b: 10 does [ b + 1 ]] ;value after execution f ;== 11 ;getting to b do first second :f ;changing b set first second :f 12 ;recheck value of f after execution f ;==13 Hope that makes sense. --Scott Jones

 [3/16] from: joel:neely:fedex at: 30-Oct-2002 6:05


Hi, Maarten, After the disclaimer that I think this is a BAAAAAAAD idea... (That's what objects are for, after all! ;-) Maarten Koopmans wrote:
> Hi, > > COnsider the following code: > > f: use [ b ][b: 10 does [ b + 1 ]] > > How can I access b later on directly? > >> fbody: [[b] b: 10 does [b + 1]]
== [[b] b: 10 does [b + 1]]
>> f: use [b] fbody >> f
== 11
>> f
== 11
>> f
== 11 (Which, incidentally, makes me wonder if there's a typo...) Since USE modifies its second argument so that words from the first argument list are rebound into another context, we take advantage of the reference to the second argument (block) to access a dummy placed there just for this purpose.
>> get fbody/1/1
== 10 ... and ...
>> set fbody/1/1 23
== 23
>> f
== 24 Of course, variations abound! As I mentioned above, this seems to be a complex way to avoid writing a more conventional object, such as:
>> foo: make object! [b: 10 f: func [][b + 1]] >> foo/f
== 11
>> foo/f
== 11
>> foo/b: 20
== 20
>> foo/f
== 21 Of course, we could make an entry in the Zeroeth Quadrennial Obfuscated REBOL contest out of this variation:
>> f: get in make object! [b: 10 f: func[][b + 1]] 'f >> f
== 11
>> f
== 11 HTH (but don't try this in public, kids! ;-) -jn- -- ; Joel Neely joeldotneelyatfedexdotcom REBOL [] do [ do func [s] [ foreach [a b] s [prin b] ] sort/skip do function [s] [t] [ t: "" foreach [a b] s [repend t [b a]] t ] { | e s m!zauafBpcvekexEohthjJakwLrngohOqrlryRnsctdtiub} 2 ]

 [4/16] from: ptretter:charter at: 30-Oct-2002 6:41


I believe 'USE is for defining locals and not globals. Paul Tretter

 [5/16] from: maarten:koopmans:surfnet:nl at: 30-Oct-2002 4:55


Yes, but not what I mean: A better sample is this: f: use [ b c ][ b: 10 c: 2 * b does [ c + 1]] Now, how do I access b directly in this case, where it has no occurence in the function body and thus is really hidden. --Maarten G. Scott Jones wrote:

 [6/16] from: gscottjones::mchsi::com at: 30-Oct-2002 7:42


From: "Maarten Koopmans"
> Yes, but not what I mean:
Too bad! :-)
> A better sample is this: > > f: use [ b c ][ b: 10 c: 2 * b does [ c + 1]] > > Now, how do I access b directly in this case, where it has no occurence > in the function body and thus is really hidden.
Even more interesting. My guess (that I don't know how to prove) is that the lexical scanner (thanks Joel, nice to learn new vocabulary) reduces this line of "data" before becoming "code." Once the code segment, pointed to by f, is ready, the other parts are no longer referenced and marked for garbage collection. Putting aside Joel's cautions (because I knew that you would be well aware of those even more so than me :-), I suspect that you are dealing with dynamic code segments and are looking for ways to manipulate them. I find this whole dynamic very interesting! (So, sorry Joel, for fun this "kid" *is* doing this at home! :-) I look forward to more interesting responses! --Scott Jones

 [7/16] from: maarten:koopmans:surfnet:nl at: 30-Oct-2002 5:33


of course.... Why would I want to access hidden, local varaiables? I have been wondering some time about "freezing" an interpreter in a way that I can pass the state around. This would be a continuation-like-thingy that can be used in distributed computing, e.g. you have a complicated computation that is serial for the first part, then can be parallelized. You'd simple freeze the script in your fave' language and send the image around. Ans that's just a sample, now if you really have imagination.... So how to proceed? First, filter all the global word from system/words, and then filter out the natives, the actions etc. Also filter out anything I/O related. Later on we may abstract ports away as "channels" where some sort of UDP transport could be used to have the data of a "channel" follow you. Can be done, so forget it for now. Get the values, and store them in a block. Now we face our first problem: objects. We need to traverse objects to filter out all I/O related variables, and they may be nested. Tail recursion anyone? Yes, see the trhead starting with http://www.escribe.com/internet/rebol/m16658.html We also me need to change make on object! types to add a 'super word for efficiently traversing the hierarchies. So now we can save all the state of all of the defined words. What do we do with anonymous objects that bind a few words in the global context? A simple way might be storing them on definition, as we are already changing make.... But what to do with words local to a value that were created using the 'use construction? Joel said:
>> fbody: [[b] b: 10 does [b + 1]]
== [[b] b: 10 does [b + 1]]
>> f: use [b] fbody >> f
== 11
>> f
== 11
>> f >> get fbody/1/1
== 10 ... and ...
>> set fbody/1/1 23
== 23
>> f
== 24 == 11 So that one is figured out as well. Changing the way functions are defined some more to intercept the current point of control flow gives us... continuation like behaviour. That can be passed on a network? Or saved on a disk? --Maarten

 [8/16] from: lmecir:mbox:vol:cz at: 30-Oct-2002 15:10


Hi Maarten, ----- Original Message ----- From: "Maarten Koopmans"
> A better sample is this: > > f: use [ b c ][ b: 10 c: 2 * b does [ c + 1]] > > Now, how do I access b directly in this case, where it has no occurence > in the function body and thus is really hidden.
If you insist to have 'b, you can: use-b: bind 'b first second :f Regards -L

 [9/16] from: gscottjones:mchsi at: 30-Oct-2002 8:52


From: "Ladislav Mecir" ...
> If you insist to have 'b, you can: > > use-b: bind 'b first second :f
Very clever. So much for my theory. Go ahead, Joel, the flogging may commence. :-( --Scott Jones

 [10/16] from: lmecir:mbox:vol:cz at: 30-Oct-2002 16:33


Hi, ----- Original Message ----- From: "Maarten Koopmans"
> Now we face our first problem: objects. We need to traverse objects to > filter out all I/O related variables, and they may be nested.
I may not understand what you are trying to say, but IMO there is no easy way to do serialization of objects even if objects are globally accessible, because the words have contexts. Example: a: make object! [x: 'x] b: make object! [x: 'x] c: a/x a/x: b/x b/x: c It is pretty complicated to write a general algorithm able to serialize A and B. Regards -L

 [11/16] from: lmecir:mbox:vol:cz at: 30-Oct-2002 16:49


Hi Scott, ...the flogging may commence... it is refreshing to learn a new english word :-) -L

 [12/16] from: g:santilli:tiscalinet:it at: 30-Oct-2002 15:00


Hi Maarten, On Wednesday, October 30, 2002, 2:33:44 PM, you wrote: MK> I have been wondering some time about "freezing" an interpreter in a way MK> that I can pass the state around. MK> This would be a continuation-like-thingy that can be used in distributed MK> computing, e.g. you have a complicated computation that is serial for MK> the first part, then can be parallelized. Since I don't think this can be done for *any* REBOL script, maybe it would just be simpler to have the scripts that want to be freezed follow some guidelines (i.e. they should be organized as an object tree, with functions to serialize non-tree structures if they are present). Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r

 [13/16] from: g:santilli:tiscalinet:it at: 30-Oct-2002 15:07


Hi Maarten, On Wednesday, October 30, 2002, 1:55:26 PM, you wrote: MK> Now, how do I access b directly in this case, where it has no occurence MK> in the function body and thus is really hidden. If you know the words, it is not difficult to access them.
>> f: use [b c] [b: 10 c: 20 does [c + 1]] >> f
== 21
>> get probe first second :f
c == 20
>> get probe first bind [b] first second :f
b == 10 If you don't know the words, you can find them (using Ladislav's functions) as long as they are in system/words. If the programmer has played some tricks so that the used words have not been added to system/words, I think that you are out of luck. (Anyway, as long as a word is not accessible in any way, there is no point in trying to serialize it, as it wouldn't have any effect on the execution of the serialized script...) Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r

 [14/16] from: maarten:koopmans:surfnet:nl at: 30-Oct-2002 18:09


You are right, this make things more complicated. Basically I am heading toward a "soft REBOL" that redefines a lot of behaviour to get serializaibility, and some sort of continuations. Anyone interested to join? --Maarten On Wed, 30 Oct 2002, Ladislav Mecir wrote:

 [15/16] from: joel:neely:fedex at: 30-Oct-2002 10:37


Hi, Scott, G. Scott Jones wrote:
> Even more interesting. My guess (that I don't know how to prove) > is that the lexical scanner (thanks Joel, nice to learn new > vocabulary) reduces this line of "data" before becoming "code." > Once the code segment, pointed to by f, is ready, the other parts > are no longer referenced and marked for garbage collection. >
AFAICT REBOL doesn't distinguish between "code" and "data". The loading process simply turns a string (what you typed into the console window or read from a disk file) into an internal structure (i.e., block) that can *either* be evaluated for effect/value or be navigated as the subject of other evaluations. It *is* my belief that the string typed into the console window has a limited lifetime, and it is possible for loading to create blocks which nothing refers to after a short while...
> (So, sorry Joel, for fun this "kid" *is* doing this at home! :-) >
Perfectly OK to play with it at home, just don't expect to make a living writing such things... ;-) (You can supply your own puns regarding the contrasts between: private public local global at home in public ;-) -jn- -- ---------------------------------------------------------------------- Joel Neely joelDOTneelyATfedexDOTcom 901-263-4446

 [16/16] from: lmecir:mbox:vol:cz at: 30-Oct-2002 20:03


> Anyone interested to join?
I am.