[REBOL] Re: making objects from block content
From: carl:cybercraft at: 27-Jun-2002 1:17
Hi Thorsten,
On 26-Jun-02, [moeller_thorsten--GMX--De] wrote:
> Hi List,
> i have some trouble with objects.
> i have an object-prototype from which i want to produce new objects.
> As well i have a block containing number, which should be the new
> objects name like this.
> a: ["2134324" "45674587" "34503"]
> the new object should look like this:
> 2134324: make prototype [ ID: 2
> Pos: 3
> .....]
Numbers cannot be made words like you have there.
> this object should be stored in a bigger block and saved to disk, so
> that i can load it later and search for specific objects.
> Hope anybody understands what i try to achieve.
Not too sure what you're trying to achieve, but if you're wanting to
search a block for numbers that are pointers to objects, that's quite
doable. ie, you might have something like this...
prototype: make object! [a: b: c: none]
blk: [
"123" make prototype [a: 10 b: "Abc"]
"4567" make prototype [a: 12 c: 3.5]
"890" make prototype [a: 1 b: "xyz"]
]
which, after they've been entered at the console, allow you to do
this...
>> find blk "4567"
== [
"4567" make prototype [a: 12 c: 3.5]
"890" make prototype [a: 1 b: "xyz"]
]
>> find/tail blk "4567"
== [make prototype [a: 12 c: 3.5]
"890" make prototype [a: 1 b: "xyz"]
]
>> copy/part find/tail blk "4567" 3
== [make prototype [a: 12 c: 3.5]]
>> reduce copy/part find/tail blk "4567" 3
== [
make object! [
a: 12
b: none
c: 3.5
]]
>> reduce copy/part find/tail blk "123" 3
== [
make object! [
a: 10
b: "Abc"
c: none
]]
>> reduce copy/part find/tail blk "890" 3
== [
make object! [
a: 1
b: "xyz"
c: none
]]
Hope that points you in the right direction.
--
Carl Read