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

Backwards Navigation on path

 [1/18] from: ammoncooke::yahoo::com at: 10-Oct-2001 21:39


Hi, How can I access a global word from inside a context? Or backwards navigate one:
>> a: make object! [
[ b: make object! [ [ c: "Object" [ ] [ d: make object! [ [ e: ../b/c [ ] [ ] ** Script Error: .. has no value ** Near: e: ../b/c
>>
Wait... Parent-Face, maybe it's Parent-Object?
>> a: make object! [
[ b: make object! [ [ c: "Object" [ ] [ d: make object! [ [ e: self/parent-object/b/c [ ] [ ] ** Script Error: Invalid path value: parent-object ** Near: e: self/parent-object/b/c hmm... No good. I know, let's try getting from a:
>> a: make object! [
[ b: make object! [ [ c: "Object" [ ] [ d: make object! [ [ e: a/b/c [ ] [ ] ** Script Error: a has no value ** Near: e: a/b/c Scrap!... Well, I guess I can go:
>> a: make object! [
[ b: make object! [ [ c: "Object" [ ] [ d: make object! [ [ e: "" [ ] [ ]
>> a/d/e: a/b/c
== "Object"
>> a/d/e
== "Object" So I got it, so what? I didn't get what I was after. Is there no other way to set a word in an object to the value of a word in another context in the same object? I think that when I am done I will submit an article concerning Objects, & Manipulation to the Zine. (that is if I can find the submital addy again...) Thanks!! Ammon

 [2/18] from: greggirwin:mindspring at: 10-Oct-2001 21:58


Hi Ammon, In this case, it should be simple:
>> a: make object! [
[ b: make object! [ [ c: "Object" [ ] [ d: make object! [ [ e: b/c [ ] [ ]
>> a/d/e
== "Object" You don't need to navigate back up the path because b and d are in the same context (someone correct me if I'm wrong please). --Gregg

 [3/18] from: ammoncooke:y:ahoo at: 11-Oct-2001 17:43


You're right! But I didn't discover that until after I sent that email, & didn't realize that it would fix my problem. (I discovered it with experiments in the console, not my actual script :)). Now let me reiderate.
>> a: make object! [
[ b: make object! [ [ c: "object" [ ] [ d: make object! [ [ e: make object! [ [ f: b/c [ ] [ ] [ ]
>> a/d/e/f
== "object" Hmm.. seems to find the nearest declaration of a word by reversing through the hierarchy....
>> a: make object! [
[ b: make object! [ [ c: "object" [ ] [ d: make object! [ [ b: make object! [ [ c: "second object" [ ] [ e: make object! [ [ f: b/c [ ] [ ] [ ]
>> a/d/e/f
== "second object" Am I not right? Is there somehow to reference to first 'b not the nearest? Thanks!! Ammon

 [4/18] from: greggirwin:mindspring at: 11-Oct-2001 22:22


Hi Ammon, What about taking a slight detour? Create a prototype object and then wrap up object "instantiation" inside a function. Here's the idea:
>> a: context [
[ b: context [c: none] [ d: context [ [ b: context [c: none] [ e: context [f: none] [ ] [ ]
>> >> make-a: does [
[ make a [ [ self/b/c: "object" [ self/d/b/c: "second object" [ self/d/e/f: self/b/c [ ] [ ]
>> aa: make-a >> aa/d/e/f
== "object" Will that approach work for you or am I still off track? --Gregg

 [5/18] from: ammoncooke:yaho:o at: 12-Oct-2001 0:53


looks like that would do it, but the idea is to create ("sh..." <he looks around to be sure no one is listening>, "RIDE") with only one word in the global context, 'RIDE. Thanks!! Ammon

 [6/18] from: ingo:2b1 at: 12-Oct-2001 11:11


Hi Ammon, you could start at the root of all evil ...
>> a: make object! [
[ b: make object! [ [ c: "object" [ ] [ d: make object! [ [ b: make object! [ [ c: "second object" [ ] [ e: make object! [ [ f: system/words/a/b/c [ ; ^^^^^^^^^^^^^^ [ ] [ ] [ ]
>> a/d/e/f
== "object" kind regards, Ingo

 [7/18] from: cyphre:seznam:cz at: 12-Oct-2001 12:12


Hi Ingo, Oops, your solution doesnot work since you are trying to assign recursive value form undone object:
>> a: make object! [
[ b: make object! [ [ c: "object" [ ] [ d: make object! [ [ b: make object! [ [ c: "second object" [ ] [ e: make object! [ [ f: system/words/a/b/c [ ; ^^^^^^^^^^^^^^ [ ] [ ] [ ] ** Script Error: f needs a value ** Near: f: system/words/a/b/c
>>
I think this should be:
>> a: make object! [
[ b: make object! [ [ c: "object" [ ] [ d: make object! [ [ b: make object! [ [ c: "second object" [ ] [ e: make object! [ [ x: does [do bind [a/b/c] 'a] [ ] [ ] [ ]
>> a/d/e/x
== "object"
>> a/b/c
== "object"
>> a/b/c: "test"
== "test"
>> a/d/e/x
== "test"
>>
Regards, Cyphre

 [8/18] from: rotenca:telvia:it at: 12-Oct-2001 14:36


Hi Cyphre,
> I think this should be: > >> a: make object! [
<<quoted lines omitted: 10>>
> [ ] > [ ]
Why not one of these: probe a: make object! [ b: make object! [ c: "object" ] d: make object! [ b: make object! [ c: "second object" ] e: make object! [ x1: do bind [b/c] 'd x2: first reduce bind [b/c] 'd x3: get in get bind 'b 'd 'c x4: get bind 'c in get bind 'b 'd 'self x5: do reduce [head insert tail to-path bind 'b 'd 'c] ] ] ] Also if 'a is not "finished", its set-words are well defined while the 'a body is executed. The delay of execution with a func is useful only if a/b/c would be defined after 'e. In this case, there are others solutions.
> Regards, > > Cyphre
--- Ciao Romano

 [9/18] from: nc-nitschvo2:netcologne at: 12-Oct-2001 10:01


Aother trick: a: context[ b: context compose[embedded-in: (self)] ] everything you write in brackets in compose is replaced before makeing the context, so the (self) is a/self. nice for double names to, like x: 2 y:3 z: 4 koord3d: context compose[x: (x) y: (y) z: (z)] -Volker Ammon Cooke wrote:

 [10/18] from: cyphre:seznam:cz at: 12-Oct-2001 15:14


Hi Romano,
> Also if 'a is not "finished", its set-words are well defined while the 'a
body
> is executed. The delay of execution with a func is useful only if a/b/c
would
> be defined after 'e. In this case, there are others solutions. >
Yes, Rebol is flexible ;) so there are lots of other solutions...I used func in my solution just for adding the a/d/x "dynamic" content. Your solutions are all "static" examples so it is up to developer which method is suitable for his purposes... regards, Cyphre

 [11/18] from: rotenca:telvia:it at: 12-Oct-2001 17:21


Hi, Volker
> Aother trick: > a: context[
<<quoted lines omitted: 3>>
> is replaced before makeing the context, > so the (self) is a/self.
If you like object trick, look at this: REBOL [] a1: context[ _self: 'self b: 2 self: context [hidden-in: '_self c: 1] ] prin "this is 'a1 :" probe a1 print ["hidden 'b in 'a1 :" get bind 'b a1/hidden-in] a2: make a1 [d: 2] prin "this is 'a2 derived from 'a1:" probe a2 print ["hidden 'b in 'a2 inherithed from 'a1 :" get bind 'b a2/hidden-in] print "now we set the hidden 'b in 'a1 at 5" set bind 'b a1/hidden-in 5 print "and also the hidden 'b in 'a2 will change:" print ["hidden 'b in 'a2 inherithed from 'a1 :" get bind 'b a2/hidden-in] a3: make a2 [e: 3] prin "this is 'a3 derived from 'a2:" probe a3 print ["hidden 'b in 'a3 inherithed by 'a2 and 'a1:" get bind 'b a3/hidden-in] -- Playing with this 'self sostitution, you can make others "magic" things. For example you can add new hidden words to an intemediate object and make an embedded function which traverse the object hierarchy to find a context which has a value for a given hidden word, and so on.
> -Volker
--- Ciao Romano

 [12/18] from: rotenca:telvia:it at: 12-Oct-2001 17:24


Hi Cyphre
> Hi Romano, > > Also if 'a is not "finished", its set-words are well defined while the 'a
<<quoted lines omitted: 7>>
> are all "static" examples so it is up to developer which method is suitable > for his purposes...
I wanted to say that there are static-like solutions also if 'a/b/c is defined after 'e.
> regards, > Cyphre
--- ciao romano

 [13/18] from: ingo:2b1 at: 12-Oct-2001 16:54


Hi Cyphre, thanks, you are right, next time i use a freshly opened rebol console for testing ... ;-) kind regards, Ingo Once upon a time Cyphre spoketh thus:

 [14/18] from: ammoncooke:ya:hoo at: 12-Oct-2001 16:39


----- Original Message ----- From: "Cyphre" <[cyphre--seznam--cz]> To: <[rebol-list--rebol--com]> Sent: Friday, October 12, 2001 3:12 AM Subject: [REBOL] Re: Backwards Navigation on path
<Snip> > I think this should be:
<<quoted lines omitted: 20>>
> == "test" > >>
You're Awesome! Thanks! Ammon

 [15/18] from: arolls:idatam:au at: 12-Oct-2001 17:52


Couldn't you still use his idea? Just put the a context and the maker/initializer function into your ride context. :) You end up with a context in a context in a context... but what the hey. Anton.

 [16/18] from: ammoncooke:yah:oo at: 12-Oct-2001 16:57


Because we are looking to get the 'b in 'a not in 'd. ;) Thanks!! Ammon

 [17/18] from: ammoncooke:yah:oo at: 12-Oct-2001 17:46


FYI, Better yet....
>> a: make object! [
[ Init: func [][ [ d/e/f: system/words/a/b/c [ ] [ b: make object! [ [ c: "Object" [ ] [ d: make object! [ [ b: make object! [ [ c: "Second Object" [ ] [ e: make object! [ [ f: none [ ] [ ] [ ]
>> a/init
== "Object"
>> a/d/e/f
== "Object" JFYI. Enjoy!! Ammon

 [18/18] from: rotenca:telvia:it at: 13-Oct-2001 13:52


Hi Ammon,
> Because we are looking to get the 'b in 'a not in 'd. ;)
Exactly what my code do. Check it.
> Thanks!! > Ammon
--- Ciao Romano

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