problems with series of objects
[1/3] from: raimund::swol::de at: 13-Aug-2000 23:58
Hi,
I try to have a series of self defined objects and pick one of the objects to
access it.
Here is the code I use:
REBOL []
book: make object! [
author:
title:
info: none
]
book1: make book []
book1/author: "Fritz the Cat"
book1/title: "That is the title of book1"
book1/info: "That is info of book1"
book2: make book []
book2/author: "Fritz the Cat"
book2/title: "That is the title of book2"
book2/info: "That is info of book2"
my-serie: [book1 book2]
this-book: make book []
this-book: first my-serie
print this-book/info
And here comes the output:
[raimund--linux]:~/Development/rebol/Tests > rebol
REBOL/View 0.9.9.4.2 1-Jun-2000
Copyright 2000 REBOL Technologies. All rights reserved.
Type DEMO to run demo if it is disabled
>> do %test_objects.r
** Script Error: Cannot use path on word! value.
** Where: print this-book/info
>>
How can I access the info from this-book? I can make an assignment like
this-book/info: "This book info" but I can not print it??
Can anyone help me on that??
Thanx
Raimund
--
<--------------------------------------------->
42 war schon immer einge gute Antwort;-))
[2/3] from: ingo:2b1 at: 13-Aug-2000 22:01
Hi Raimund,
I'll step to your program, and maybe we'll find
out together ...
Once upon a time [raimund--swol--de] spoketh thus:
> I try to have a series of self defined objects and pick one of the objects to
> access it.
<<quoted lines omitted: 5>>
> info: none
> ]
REBOL> help book
object with fields:
author (none) none
title (none) none
info (none) none
> book1: make book []
> book1/author: "Fritz the Cat"
> book1/title: "That is the title of book1"
> book1/info: "That is info of book1"
REBOL> help book1
object with fields:
author (string) "Fritz the Cat"
title (string) "That is the title of book1"
info (string) "That is info of book1"
Up to now, it seems ok.
> book2: make book []
> book2/author: "Fritz the Cat"
> book2/title: "That is the title of book2"
> book2/info: "That is info of book2"
>
> my-serie: [book1 book2]
REBOL> help my-serie
MY-SERIE is a block of value: [book1 book2]
You might get uneasy here, let's see what follows.
> this-book: make book []
>
> this-book: first my-serie
REBOL> help this-book
THIS-BOOK is a word of value: book1
Ahhh, yes. You see, your block contains words, that
by pure coincidence have the same name as your
objects, but that doesn't mean that they are bound
to the same values.
To get your "objects" into your block, you have to
reduce it, like
REBOL> my-serie: reduce [book1 book2]
REBOL> help my-serie
MY-SERIE is a block of value: [
make object! [
author: "Fritz the Cat"
title: "That is the title of book1"
info: "That is info of book1"
]
make object! [
author: "Fritz the Cat"
title: "That is the title of book2"
info: "That is info of book2"
]]
REBOL> this-book: first my-serie
REBOL> print this-book/info
That is info of book1
I hope this helps
Ingo
PS: Don't assume your help will give you as
much info as you've seen here. This is
my patched version ...
[3/3] from: larry:ecotope at: 13-Aug-2000 14:18
Hi Raimund
You are close. The problem is the items in my-serie are words, not the
values (objects, in this case) to which the words refer.
Try
this-book: get first my-serie
print this-book/info
The GET will dereference the word 'book1, returning the object itself.
If you want the serie to contain the actual objects, you can do this
my-serie: reduce [book1 book2]
then your original access code works
this-book: first my-serie
print this-book/info
HTH
-Larry
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted