*****BEGINNER'S QUESTIONS*****
Dr. Turk,
I hope you don't mind my replying as I'm not much
more than a beginner myself. I remember the
difficulties I had when I was first starting out with
Rebol. I still don't understand 90% of the stuff
people talk about on this mailing list but I've
learned enough Rebol to enjoy it.
I think it is best to read through the core guide
and then the Rebol for Dummies first before trying
Rebol - The Official Guide. I started out with The
Official Guide and knocked my head against it for 3
months, and while I'm sure it improved my character, I
wouldn't recommend it for a beginner.
There is a typo in the script you're using; try
the one attached. It is an amazing script; I've been
playing with it the past couple of days. I've just
started to learn View and have been working on an
interface for this script. The only databases I've
done in Rebol have been small flat-files and they look
really bloated compared to this.
I've tried to answer the questions you raised as best
I could, I hope it helps.
To see the data you have entered use ==>
probe database
You can't print an object; use probe.
The database block contains the database when it is
loaded into Rebol. The %data file is just used to
store the database to disk.
All the database functions work with database block.
load-data loads the disk copy of the database from
disk and into the block called database.
save-data writes the database block to the %data file,
when you are done making modifications to the
database.
Thus find-data and remove-data can be called after you
create a record with insert-data. Those functions only
work with the database block and have nothing to do
with the %data file.
Hash
I've added a line that turns the database block from a
block! type to a hash!
Change an Email Address
First look-up the record to change with find-data and
assign it to a variable ==>
x: find-data [EMAIL PROTECTED]
then probe x to see the object ==>
probe x
To change bill's email address use ==>
x/email: [EMAIL PROTECTED]
When you call save-data and then load-data you can use
find-data with the new email address.
#################################################
Email Contact Database
REBOL [Title: "Email Contact Database"]
db-file: %data
record: context [name: email: phone: web: none]
database: []
load-data: has [data] [
data: load/all db-file
clear database
foreach item data [
item: make record item
repend database [item/email item]
database: to-hash database
]
]
save-data: has [data] [
data: copy []
foreach [key obj] database [
append/only data third obj
]
save db-file data
]
find-data: func [email] [select database email]
remove-data: func [email] [remove/part find database
email 2]
insert-data: func [email' name' phone' web'] [
repend database [
email'
make record [
email: email'
name: name'
phone: phone'
web: web'
]
]
]
##################################################
--- "Dr. Louis A. Turk" <[EMAIL PROTECTED]>
wrote:
> Dear Carl,
>
> I am amazed that such a small amount of code can do
> so much, and also that
> the creator of this language himself would help me
> like this. Many thanks!
>
> I have some questions. I have been studying your
> code carefully trying to
> learn how it works. I've been on this list for
> quite a while, but have
> only recently taken time to buy Ralph's book and
> Elan and John's book to
> really get serious about learning the language. I'm
> a real beginner, so
> please excuse me if my questions betray that fact.
>
> So far I have figured out how to use your functions
> to enter data into a
> record, and then save it to a file. By entering
> "print read %data.r" at
> the command line, I am able to see that I have
> entered the data
> successfully. So I think I understand how to use
> insert-data and
> save-data. However, when I type load-data I get an
> error message ("blk
> has no value"); what am I doing wrong? Also, I
> assume that I must learn
> how to get load-data to work before find-data and
> remove-data will work;
> but to keep from having to ask you later, how are
> these two functions used?
>
> I want to use this database for an email list. Most
> of the data remains
> the same, but email addresses change often.
> Sometime I do not even have a
> name---only an email address that has to be removed
> or changed. How do I
> change an email address?
>
> You say:
>
> > If you expect to grow this database to a large
> >size, you will want to MAKE HASH! the database when
> you load
> >it.
>
> Will this modification do it?:
>
> >load-data: has [data] [
> > data: make hash! load/all db-file
> > clear database
> > foreach item blk [
> > item: make record item
> > repend database [item/email item]
> > ]
> >]
>
> Will your code work with Rebol/View also? Am I
> correct in assuming that
> View would be ideal for creating a user interface
> for the database?
>
> Many thanks for your help, and for creating a truly
> exciting language.
>
> Louis
>
>
>
> At 08:28 AM 4/9/2001 -0700, you wrote:
> >What!? You just want us to just whip out an object
> database, eh? ;)
>
> Well, I wasn't expect anyone to whip out one
> especially for me,
>
> >Ok, why not.... Here is a small "contacts"
> database keyed by email.
> >You can expand or reduce the record definition
> without corrupting
> >or affecting the database.
> >
> >REBOL [Title: "Email Contact Database"]
> >
> >db-file: %data.r
> >record: context [name: email: phone: web: none]
> >database: []
> >
> >load-data: has [data] [
> > data: load/all db-file
> > clear database
> > foreach item blk [
> > item: make record item
> > repend database [item/email item]
> > ]
> >]
> >
> >save-data: has [data] [
> > data: copy []
> > foreach [key obj] database [
> > append/only data third obj
> > ]
> > save db-file data
> >]
> >
> >find-data: func [email] [select database email]
> >
> >remove-data: func [email] [remove/part find
> database email 2]
> >
> >insert-data: func [email' name' phone' web'] [
> > repend database [
> > email'
> > make record [
> > email: email'
> > name: name'
> > phone: phone'
> > web: web'
> > ]
> > ]
> >]
> >
> >You can expand/contract the record definition at
> any time.
> >
> >This is untested... but should be close to working,
> less a few
> >minor typos. If you expect to grow this database
> to a large
> >size, you will want to MAKE HASH! the database when
> you load
> >it.
> >
> >-Carl
> >
> >PS: The remove/part on find really does work.
> Remove none is
> >allowed in Core 2.5.
> >
> >
> >-----Original Message-----
> >From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]]On Behalf Of
> >Dr. Louis A. Turk
> >Sent: Monday, April 09, 2001 4:35 AM
> >To: [EMAIL PROTECTED]
> >Subject: [REBOL] Object Database
> >
> >
> >I am trying to learn how to make an object database
> using REBOL. I need a
> >simple, but complete, working example. Can anyone
> supply one?
> >
> >Also, what are probably dumb questions:
> >
> >1. If an object database contains data, will that
> data be lost if another
> >field is added?
> >
> >2. Is there any way to change the name of an object
> in a database without
> >losing the data in the object?
> >
> >3. Would it be possible to use email addresses for
> the names of the objects?
> >
> >Thanks in advance for any help.
> >
> >Louis
> >
> >
> >--
> >To unsubscribe from this list, please send an email
> to
> >[EMAIL PROTECTED] with "unsubscribe" in the
> >subject, without the quotes.
> >
> >
> >--
> >To unsubscribe from this list, please send an email
> to
> >[EMAIL PROTECTED] with "unsubscribe" in the
> >subject, without the quotes.
>
> --
> To unsubscribe from this list, please send an email
> to
> [EMAIL PROTECTED] with "unsubscribe" in the
> subject, without the quotes.
>
__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/
--
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the
subject, without the quotes.