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
Reaccess Lists in different functions
Started by newbie00, Apr 15 2007 02:43 AM
6 replies to this topic
#1
Posted 15 April 2007 - 02:43 AM
#2
Posted 15 April 2007 - 06:31 AM
post your code?
reedbeta.com - developer blog, OpenGL demos, and other projects
#3
Posted 15 April 2007 - 07: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
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
#4
Posted 16 April 2007 - 07:37 AM
newbie00 said:
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
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.
#5
Posted 16 April 2007 - 09:59 AM
Why would you want to use Prolog in the first place? :huh:
#6
Posted 16 April 2007 - 12:46 PM
its a project am working on for a stock take system and i have to use prolog :s
#7
Posted 16 April 2007 - 02:05 PM
newbie00 said:
its a project am working on for a stock take system and i have to use prolog :s
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?
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











