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

[REBOL] Re: Objects, references & values

From: robert:muench:robertmuench at: 19-Dec-2001 16:31

> -----Original Message----- > From: [rebol-bounce--rebol--com] [mailto:[rebol-bounce--rebol--com]]On Behalf Of > Romano Paolo Tenca > Sent: Wednesday, December 19, 2001 3:29 PM > To: [rebol-list--rebol--com] > Subject: [REBOL] Re: Objects, references & values > I do not understand what you want to say. I can add it to a hash! datatype: > > >> x: context [a: 2] > >> nameref: in x 'a > == a > >> append make hash! 1 nameref > == make hash! [a] > > the value of 'a in the hash datatypes changes with the value of a in the x > context
Hi, yes you can add it to the hash!, of course. But what do you want to search for in the hash!? You can only search for 'a not the value 'a is refering to. That's my problem. Example: hash!: ["romano" address-object] Now I can search for "romano" and get the address-object. In this case I have to update the hash! if your name changes. Ok, to solve this, one could say: Hey, we have an address-object that always contains the actual name: hash!: [address-object/name address-object] But now I don't want to search for 'address-object/name but for the value, which is "romano" in our case. So what I would like to have is find using reduce to get the value of address-object/name while searching. That's why I would suggested to tag the address-object/name as a to-get-path. With this you could write: index1: to-get-path address-object/name hash!: [index1 address-object] Now if find iterates through the hash! and reaches an entry that is associated with a to-get-path, it evaluates the value. However, there is an other way to be able to use find with a hash! and referenced values. You have to double reduce the hash! before sending it to find. (See attached script below). The question is what happens internally to the hash! datastructure? Is it build-up new? This would result an a temporary new hash! data-structure used for find with the actual values. I hope you now understand what I mean.
> This is true. But load/save are for loading code and related data struct not > for snapshot of data. This seems to me a relational database work.
Yep, but IMO it's unnatural to faltten rebol objects to be stored in an RDBMS. What do you do, if your objects are not all equalle structured? The RDBMS can't handle that. It always needs the table specificaction a priori and complete. Robert Rebol[] myobj!: make object! [ name: string! 0 note: string! 0 ] myobjects1: make hash! [] myobjects2: make hash! [] obj1: make myobj! [name: "Robert" note: "Rebol"] ; this is the value obj1/name value: in obj1 'name ; this is an obj1 reference insert myobjects1 [1 obj1] ; this is the value obj1/name insert myobjects2 [value 1] probe obj1 probe get value probe reduce myobjects1 probe reduce myobjects2 probe reduce reduce myobjects2 print "--- Trying find in hash!" if find/case reduce myobjects2 "Robert" [print "Found!"] ; this one fails if find/case reduce reduce myobjects2 "Robert" [print "Found!"] ; this one hits ; changing the object obj1 and all of its references obj1/name: "robert" probe obj1 probe get value probe reduce myobjects1 probe reduce reduce myobjects2 print "--- Trying find in hash!" if find/case reduce myobjects2 "robert" [print "Found!"] ; this one fails if find/case reduce reduce myobjects2 "robert" [print "Found!"] ; this one hits halt