[REBOL] Re: Objects in VID
From: brett::codeconscious::com at: 15-Mar-2002 20:05
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.
> 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]
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,
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.
P.S What city are you based in Ashley? Just curious as I'm in Sydney.