Jump to content


Reaccess Lists in different functions


6 replies to this topic

#1 newbie00

    New Member

  • Members
  • Pip
  • 4 posts

Posted 15 April 2007 - 02:43 AM

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

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 4782 posts
  • LocationBellevue, WA

Posted 15 April 2007 - 06:31 AM

post your code?
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 newbie00

    New Member

  • Members
  • Pip
  • 4 posts

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

#4 newbie00

    New Member

  • Members
  • Pip
  • 4 posts

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



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 Nick

    Senior Member

  • Members
  • PipPipPipPip
  • 1225 posts

Posted 16 April 2007 - 09:59 AM

Why would you want to use Prolog in the first place? :huh:

#6 newbie00

    New Member

  • Members
  • Pip
  • 4 posts

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 Nick

    Senior Member

  • Members
  • PipPipPipPip
  • 1225 posts

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
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?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users