Objects in VID
[1/4] from: atruter:hih:au at: 15-Mar-2002 12:10
Given, f1: "Field 1" obj: make object! [f2: "Field 2"] how come view layout [f1: text obj/f2] or f2: obj/f2 view layout [f2: text f1] work, but: view layout [obj/f2: text f1] does not? and yields a different error message to: view layout [f1: text obj/f2 obj/f2: text f1] Regards, Ashley
[2/4] from: brett::codeconscious::com at: 15-Mar-2002 20:05
Hi Ashley, The thing to remember is that LAYOUT is a function that accepts an argument of type block! That block contains a series of values, which LAYOUT interprets in order to build you a view object. The block must conform to the grammar of VID that LAYOUT is expecting. So the meaning of the values in that block are likely to be different from REBOL script you might enter at the console. So to take your examples...
> f1: "Field 1" > obj: make object! [f2: "Field 2"] > > how come > > view layout [f1: text obj/f2]
F1 is a word that is set to a text object, the text object is initialised with some text data which is the result of evaluating obj/f2.
> or > > f2: obj/f2 > view layout [f2: text f1]
Same structure as last one.
> work, but: > > view layout [obj/f2: text f1]
The first value in this block is a set-path! See this:
>> type? first [obj/f2: text f1]
== set-path! There are a number of datatypes that LAYOUT accepts as the first in the specification block, but set-path! is not one of them. That is why you get the "Misplaced item: obj/f2:" message. Actually I suspect that a set-path! is not part of the VID grammar so you cannot use it anywhere in VID except between "(" and ")" or in a DO block of code. To get a field F2 inside an object OBJ to be set by layout to a TEXT object you would need to enclose the call to LAYOUT inside the context of the OBJ, like this: f1: "Field 1" obj: context [ f2: none ; Ensures OBJ has an f2 field view layout [f2: text f1] ] Try it, then you can do this:
== "Field 1"
> does not? and yields a different error message to: > > view layout [f1: text obj/f2 obj/f2: text f1]
This has an error for the same reason as the last example. It is different in the message though because LAYOUT encounters the set-path! value "obj/f2:" at a different point in the VID grammar. In this case, encountering it upsets LAYOUT during it interpretation of your specification. You could argue that LAYOUT should give a meaningful error message in this case - but that's probably a whole different discussion. So the sum up is that a LAYOUT block is a dialect. Dialects share the same datatypes as "ordinary" REBOL but differ in their grammar. Sometimes the dialects provide points in their grammar where code will be evaluated exactly like "ordinary" REBOL code, but usually you should expect otherwise, because a dialect should be purpose designed to offer better leverage over a specific problem than "ordinary" REBOL code. Side note: I keep quoting "ordinary" because (a) REBOL is not ordinary ;^) and (b) one realises after a while that the meaning of REBOL code is entirely determined by its interpretation - so attention is drawn to *what* evaluates a block. Regards, Brett Handley. P.S What city are you based in Ashley? Just curious as I'm in Sydney.
[3/4] from: rotenca:telvia:it at: 15-Mar-2002 14:20
> f1: "Field 1" > obj: make object! [f2: "Field 2"] > view layout [obj/f2: text f1] > > does not? and yields a different error message to:
You can do: view layout bind [f2: text f1] in obj 'self or obj: make object! [ f2: "Field 2" view layout [f2: text f1] ] or obj: make object! [ f2: "Field 2" ly: layout [f2: text f1] ] view obj/ly or obj: make object! [ f2: "Field 2" ly: [f2: text f1] ] view layout obj/ly Layout accepts only set-word (not set-path) before a style name.
> view layout [f1: text obj/f2 obj/f2: text f1]
The error is different because layout "thinks" that the set-path is a facet. In this case, it assigns the set-path to the f1 definition, because only a set-word or one of the svv/vid-words or a style name can signal the start of a new face definition. --- Ciao Romano
[4/4] from: atruter:hih:au at: 18-Mar-2002 11:14
Thanks Brett & Romano, that was exactly what I was looking for. Brett, I'm located in Melbourne - slowly spreading the REBOL word down here ;) One day we may even have enough people for a REBOL User's Group (RUG)!!! Regards, Ashley