[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Tue, 12 Oct 2004 22:12:33 +0000 (UTC) 
Subject:Re: database 
From:A . Sloman 
Volume-ID: 

Wayn wrote

> how do i make the database to record (into list form)
> everything that is typed to it via readline?

You can add the result  of readline to the pop11 database
just by applying the procedure add to to the result of readline
(which is always a list, possibly empty).

For example:

    [] -> database;

    repeat forever
        lvars line;
        readline() -> line;
        quitif(line = [bye]);
        add(line);
    endrepeat;

    database ==>

> i put a
> load save file( upon exit it should save to disk) in
> the main code page.  what would the code look like for
> such a thing?

See HELP storedata

After you have constructed your database (which should be
a list of lists), you can use the procedure storedata
to store it in a file.

    storedata('Mydata.p');

then later you can restore the previously stored database,
e.g by doing

    load Mydata.p

You can test the effect of that by printing out the
database

    database ==>

> here is code to chatbot/db   it crashes whenever it
> doesnt match list.

Instructions to run your code, and how to crash it will
make it easier to help you.


> wont delete or add data during
> program run. i also want to to remember each current
> user and be able to switch users and remember each
> one.  how do i do that

Just store each user's database in a different file,
e.g. 'fred.p' 'mary.p' 'joe.p'.

Load the database when the user returns. You can check
whether a file exists using
    sys_file_exists(filename)

That returns true or false.


> and what is wrong?
>
> ................................................
>
 [] -> database;
 load 'mydatabase.p';

define converse();

    vars list,answer,name;
    [hello] =>
    [what is your name?] =>
    readline() -> name;
    [pleased to meet you ^^name] =>
    [well - what do you want to talk about?] =>
    repeat forever
        readline() -> list;
    quitif(list = [bye]);
        storedata('mydatabase.p');
        answer(list) =>
    endrepeat;
    [goodbye ^^name - talk to you another time.] =>
enddefine;

I used 'ENTER jcp' to format the procedure, as it was harder to
read without the indentation.

You have put the call of storedata inside the loop. That would
overwrite the saved file each time with the current value
of database, which is just the empty list because you have
not added anything to it.

See the help file: storedata is designed to store the whole
database, e.g. after a run of your program.

To build up the database use 'add' with each item, not storedata.
In pop11 the database is not a file but a list.


 ;;; check the facts (word [thing] - meaning) in the
 database. if not there(add it)

define interpret(list) -> response;
    vars thing,whatis,meaning;
    if list matches [??thing is ??meaning] then
        verify(thing, meaning) -> response;
    elseif list matches [what is ??thing] then
        whatis(thing) -> response;
    else [please inform me ^^name] ->response;
    endif;
enddefine;

Your 'else' clause uses the variable "name" when nothing
before that line has given it a value.

If you use "^^" with a variable whose value is not a list,
you'll get a 'list needed' error.

    vars name;
    99-> name;

    [ 1 2 3 ^^name]=>
    ;;; MISHAP - LIST NEEDED
    ;;; INVOLVING:  99

If nothing has been assigned to name the
INVOLVING line will have <undef name>


define forget(list) -> response;
    vars thing,meaning;
    remove([^^thing is ^^meaning]);
    [i have removed that info from my knowledge base.] ->
    response;
enddefine;

In the above procedure the input is 'list' but is not
used anywhere.

In the remove command you use the variables 'thing'
and 'meaning' without first assigning anything to them.


When developing programs it is important to test
*each* procedure as you write it. Make sure it works
before you move on to the next one.

If you write a lot of procedures and then try to test them all in
one go, you will find it hard to track down the sources of
errors. That also makes it hard for others to help you.

You can't really expect other people to do that for you.

Your 'answer' procedure has a long sequence of
conditions and actions. You need to test each condition
separately by giving the procedure appropriate inputs
to test that the right result is produced in every case.

I hope that helps.

Aaron