PDA

View Full Version : Reaccess Lists in different functions


newbie00
04-14-2007, 07:43 PM
Hi all

I am having problem with using lists in SWI-prolog, my problem is that i have an application that reads a text file, which then puts the data in the text file into a list to be used later by the application. So far i am able to read the file and insert the data into a list, although when i conti with my application i cant seem to add more data to the list, i used before all that happens is that the list gets overwriten with the new data, and its killin me.

any help would be great.
Cheers

Reedbeta
04-14-2007, 11:31 PM
post your code?

newbie00
04-15-2007, 12:31 AM
read_file :-
see(user),
write('Enter name of file to browse: '), read(File),
open(File, read, ID),
repeat,
read(ID, X),
insert(X,ID,[X|ID]),
X == end_of_file,
nl,nl,
close(ID).

insert(X,T,[X|T]) :-
write([X]).

thats the code where the file is read then the data in the file is added to the list which is called insert, then gets displayed, but when i use insert somewhere else it over rides the current data. idea why and what am i doing wrong?

Cheers

newbie00
04-16-2007, 12:37 AM
read_file :-
see(user),
write('Enter name of file to browse: '), read(File),
open(File, read, ID),
repeat,
read(ID, X),
insert(X,ID,[X|ID]),
X == end_of_file,
nl,nl,
close(ID).

insert(X,T,[X|T]) :-
write([X]).

thats the code where the file is read then the data in the file is added to the list which is called insert, then gets displayed, but when i use insert somewhere else it over rides the current data. idea why and what am i doing wrong?

Cheers



i have been told that i should use assert to to remember the list, although how would you implement assert to remember a list which contains data from a file that has been read, as i tried it but i get an error saying something like no permission.

Nick
04-16-2007, 02:59 AM
Why would you want to use Prolog in the first place? :huh:

newbie00
04-16-2007, 05:46 AM
its a project am working on for a stock take system and i have to use prolog :s

Nick
04-16-2007, 07:05 AM
its a project am working on for a stock take system and i have to use prolog :s
An actual commercial stock take system was implemented in SWI-Prolog? :wacko:

I have only one advise: Rewrite the whole thing in C#. It will take less time than messing with Prolog every time you need to add or change a feature.

By the way, what does all this have to do with Artificial Intelligent for Game Development?