making objects from block content
[1/5] from: moeller_thorsten::gmx::de at: 26-Jun-2002 13:37
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
.....]
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.
Any ideas are welcome!!!!
Thorsten
[2/5] 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.
<<quoted lines omitted: 6>>
> 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
[3/5] from: greggirwin:mindspring at: 26-Jun-2002 10:58
Hi Thorsten,
<< 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"]
>>
As Carl pointed out, it's not generally a good idea to use numbers as IDs,
but it is technically possible in REBOL (where it wouldn't be in most other
languages).
>> a: ["2134324" "45674587" "34503"]
== ["2134324" "45674587" "34503"]
>> id: to set-word! first a
== 2134324:
>> set 'id make object! [x: 1]
>> probe id
make object! [
x: 1
]
--Gregg
[4/5] from: greggirwin:mindspring at: 26-Jun-2002 11:00
Hi Again,
As an addenduem, it may not work at all in your case as LOAD will very
likely not recognize numbers as valid set-words.
--Gregg
[5/5] from: joel:neely:fedex at: 27-Jun-2002 17:36
Hi, Thorsten,
[moeller_thorsten--GMX--De] wrote:
> Hi List,
> i have some trouble with objects.
<<quoted lines omitted: 9>>
> so that i can load it later and search for specific objects.
> Hope anybody understands what i try to achieve.
I'm not sure I do, so let me ask some dumb questions.
* Why are you using objects instead of blocks of key/value pairs?
* Do the objects have behavior (functions)?
* If so, do the objects all have the *same* set of behaviors?
* Do the behaviors need to be saved, or just the data-like
attributes of the blocks?
* Why do you want to use numbers as the "names" of the blocks?
* Could you use the numbers as keys instead?
--
; Joel Neely joeldotneelyatfedexdotcom
REBOL [] do [ do func [s] [ foreach [a b] s [prin b] ] sort/skip
do function [s] [t] [ t: "" foreach [a b] s [repend t [b a]] t ] {
| e s m!zauafBpcvekexEohthjJakwLrngohOqrlryRnsctdtiub} 2 ]
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted