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

Which? [Object! Block!]

 [1/13] from: ammoncooke::yahoo::com at: 27-Sep-2001 1:40


Hi, I am trying to determine which is better for what( object! block!). I have been through the Core manual time & again studying both of them, but nether suits me. I need to be able to add to the *values*, but I can't see a way to do that with object!, so because of this I suppose I would have to use a block!. BUT I NEED to be able to protect global name space. Did I just miss something, or is there really no way to add values to an object? Is there a more simple way to dynamically edit the series & protect the global name space? (i.e. a: make object! [b: "c"] ; now is there a way to add: d: "e" ; to a? Thanks!! Ammon

 [2/13] from: al:bri:xtra at: 27-Sep-2001 18:51


Ammon asked:
> a: make object! [b: "c"] > ; now is there a way to add:
<<quoted lines omitted: 3>>
>> a: make a [d: "e"] >> probe a
make object! [ b: "c" d: "e" ] I hope that helps! Andrew Martin ICQ: 26227169 http://zen.scripterz.org

 [3/13] from: ammoncooke:y:ahoo at: 27-Sep-2001 2:08


Oh, cool! that was simple. ;)) Thanks!! Ammon

 [4/13] from: cyphre:volny:cz at: 27-Sep-2001 10:06


Hi Ammon and Andrew, Just one important note... Your method of adding new value(s) into same object is common but be careful of clonnig objects when the parent object contains another nested object(s)!!! See this example:
>> a: make object! [x: 5 y: make object! [z: 10]] >> b: make a [] >> probe b
make object! [ x: 5 y: make object! [ z: 10 ] ]
>> a/x
== 5
>> b/x
== 5
>> a/x: 8
== 8
>> b/x ;thats OK
== 5
>> a/y/z
== 10
>> b/y/z
== 10
>> b/y/z: 3
== 3
>> a/y/z ;Ups! both objects 'a and 'b have "shared" nested object 'x which
can lead to problems in yourcode!! == 3 In that situation you have to make your own function for recursive re-building of nested objects(could be faster that second solution) or use this second solution:
>> a: make object! [x: 5 y: make object! [z: 8]] >> b: do mold a ; "do mold" clones whole object with all its nested objects
;this method is slower when cloning bigger objects than method of recursion...
>> probe b
make object! [ x: 5 y: make object! [ z: 8 ] ]
>> a/y/z
== 8
>> b/y/z
== 8
>> b/y/z: 1
== 1
>> a/y/z
== 8
>>
I hope that next release of REBOL will contain 'EXTEND function for adding values into objects as Carl said some time ago. Also something like make/deep will be useful...but this is stil repeated and very old topic ;-) Another feature what I'm missing when working is DOing some code in specified context since Rebol's current DO does the code always in global context. Maybe something like "do in a [x: 10]" should be useful... Regards, Cyphre

 [5/13] from: ammoncooke::yahoo at: 27-Sep-2001 3:35


Wait! Let's see here: lyts: make object! [lyt: make object![wrd: tp: spc: vls: none]] tmp-lyts: [[lyt1: layout [text "layout1"]]] foreach l tmp-lyts[ nw-lyt: compose/deep[ wrd: (first l) tp: (second l) spc: [(third l)] (if (length? l) > 3 [ "vls:" fourth l ]) ] lyts: make lyts [ probe compose [(to-set-word first l) (to-word "make lyt[") (nw-lyt) (to-word "]")] ] ]
>> probe lyts
make object! [ lyt: make object! [ wrd: none tp: none spc: none vls: none ] ] why doesn't it add the composed block? Thanks!! Ammon

 [6/13] from: al:bri:xtra at: 27-Sep-2001 20:51


Cyphre wrote:
> Your method of adding new value(s) into same object is common but be
careful of cloning objects when the parent object contains another nested object(s)!!! In which case, one needs a 'clone function something like this: [ Rebol [ Name: 'Clone Title: "Clone" File: %Clone.r Home: http://zen.scripterz.org Author: "Andrew Martin" eMail: [Al--Bri--xtra--co--nz] Date: 27/Sep/2001 Acknowledgements: "Erin A. Thomas" Purpose: { Clone objects by copying objects inside. } Example: [ New_object: Clone Original_Object [] ] ] Clone: function [ {Clones all sub-objects and hashes, so there are no multiple references.} [catch] Object [object!] "The object to clone." Block [block!] "Extra code for this object." ][ Cloned Member ][ throw-on-error [ Cloned: make Object Block foreach Word next first Object [ Member: get in Cloned :Word if same? Member get in Object :Word [ set in Cloned :Word either object? Member [ Clone Member [] ][ either any [ series? Member port? Member bitset? Member ][ copy/deep Member ][ Member ] ] ] ] Cloned ] ] ] I hope that helps! Andrew Martin Fingers worked to the bone... ICQ: 26227169 http://zen.scripterz.org

 [7/13] from: al:bri:xtra at: 27-Sep-2001 21:06


Ammon asked:
> why doesn't it add the composed block?
Because this line here:
> probe compose [(to-set-word first l) (to-word "make lyt[")
(nw-lyt) needs to have a set-word! before the 'compose. Also:
> "vls:" fourth l
should be: vls: fourth l perhaps? Also, if you're just storing layouts, why not just store the block of words? For example: Layouts: [ layout1 [text "layout1"] ] then access it by: view layout layouts/layout1 ? Andrew Martin Fully compose-d rebolutionary... ICQ: 26227169 http://zen.scripterz.org

 [8/13] from: al:bri:xtra at: 27-Sep-2001 21:13


Cyphre wrote:
> Another feature what I'm missing when working is DOing some code in
specified context since Rebol's current DO does the code always in global context. Maybe something like "do in a [x: 10]" should be useful... I've found this helpful: object: make object! [x: 123] do bind [x: 10] in object 'self to execute code that should be in the object's context. For example:
>> object: make object! [x: 123] >> do bind [x: 10] in object 'self
== 10
>> probe object
make object! [ x: 10 ] I hope that helps! Andrew Martin Writing Rebol code while waiting for 21.5MB of silly program to download... ICQ: 26227169 http://zen.scripterz.org

 [9/13] from: cyphre:volny:cz at: 27-Sep-2001 12:30


Hi Andrew,
> I've found this helpful: > object: make object! [x: 123]
<<quoted lines omitted: 7>>
> x: 10 > ]
Yes, but this method just bind already defined words to specified context so it is not for doing block of "universal" code:
>> object: make object! [x: 123] >> do bind [e: 8] in object 'self
== 8
>> object/e
** Script Error: Invalid path value: e ** Where: halt-view ** Near: object/e
>> e
== 8
>>
Regards, Cyphre

 [10/13] from: al:bri:xtra at: 28-Sep-2001 3:53


> Yes, but this method just bind already defined words to specified context
so it is not for doing block of "universal" code:
> >> object: make object! [x: 123] > >> do bind [e: 8] in object 'self
<<quoted lines omitted: 6>>
> == 8 > >>
So, we want set-word! to expand the context? In which case then, something like the scanner that operates on object! to determine the words in it would be useful. IOW, find any set-word values in the block (may be dive into block! values as well? perhaps using block parse), rewrite the containing object with those set-words, then bind and do the block. Andrew Martin [Sounds of Rebolutionary fervour...] ICQ: 26227169 http://zen.scripterz.org

 [11/13] from: ammoncooke::yahoo at: 27-Sep-2001 12:29


----- Original Message ----- From: "Andrew Martin" <[Al--Bri--xtra--co--nz]> To: <[rebol-list--rebol--com]> Sent: Thursday, September 27, 2001 2:06 AM Subject: [REBOL] Re: Which? [Object! Block!]
> Ammon asked: > > why doesn't it add the composed block? > > Because this line here: > > > probe compose [(to-set-word first l) (to-word "make lyt[") > (nw-lyt) > > needs to have a set-word! before the 'compose.
Why? It currently returns a perfect make object!. Not to question your knowledge, but to enlargen mine. ;)
> Also: > > > "vls:" fourth l > > should be: > > vls: fourth l > > perhaps?
Yes, & no: nw-lyt: compose/deep[ wrd: [(first l)] tp: [(second l)] spc: [(third l)] (if [length? l > 3] [ vls: fourth l ]) ] returns: ** Script Error: Out of range or past end ** Where: do-boot ** Near: fourth l I guess compose doesn't execute an 'if?
> Also, if you're just storing layouts, why not just store the block of
words?
> For example: > > Layouts: [ > layout1 [text "layout1"] > ] >
because. ;) Well, it is difficult for me to explain... One reason is that I need to be able to handle ALL parameters of a layout. If you look at the object 'lyt which I have defined, make object! [ wrd -- (word) The name of the layout tp -- (type) Maybe I should use a different name, but it contains 'layout + any refinements spc -- (spec) The specs of the layout pr -- (parameters of the refinements) Currently it is not always created, but I will probably change that ] then the other reason is that the layouts get DOne when they are viewed. I need them to not be in the global namespace. Block! maybe better, I am just not sure. Thanks!! Ammon

 [12/13] from: al:bri:xtra at: 28-Sep-2001 5:59


Ammon wrote:
> compose [(to-set-word first l) (to-word "make lyt[") (nw-lyt)
You need a set-word for the outer object. to-set-word first l compose ; etcetera.
> (if [length? l > 3] [ > vls: fourth l > ])
This is slightly better: (vls: none if 3 < length? l [vls: fourth l])
> then the other reason is that the layouts get DOne when they are viewed.
I need them to not be in the global namespace. Block! maybe better, I am just not sure. perhaps better would be to surround each layout with it's own context? Like: o: make object! [ f: none l: layout [f: field "default"] ] that way the 'f in the layout dialect refers to the f in o? By the way, your code seems very confused. perhaps you could rewrite it with better name choices and start with something really simple? Andrew Martin ICQ: 26227169 http://zen.scripterz.org

 [13/13] from: ammoncooke:yaho:o at: 27-Sep-2001 14:32


Your help has been very appreciated. It has enlighted me greatly. I will take this one back to the drawing board. ;) I will let you know if I need more help. Thanks!! Ammon

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