Hello,
I would like to know the best way of reading and writing to more than one file at a time. What my program does is it consults a file for patterns and uses them for output to the screen. In some cases I will need to create another file for a new user whereby I will still need the pattern file open to give responses to screen but to also write pattern matches to the users file.
What would be the best approach? Is it possible to consult two files at once and could someone explain the built-in load and save functions in prolog.
All help greatly appreciated.
Reading input from files PROLOG
Started by ruman29, Mar 08 2007 04:40 PM
5 replies to this topic
#1
Posted 08 March 2007 - 04:40 PM
#2
Posted 08 March 2007 - 05:09 PM
Don't do file I/O in prolog.
I'm serious. It's a horrible language for that. Even a functional language would be better, but file I/O really is a task best suited to a procedural/imperative language.
I'm serious. It's a horrible language for that. Even a functional language would be better, but file I/O really is a task best suited to a procedural/imperative language.
reedbeta.com - developer blog, OpenGL demos, and other projects
#3
Posted 08 March 2007 - 07:49 PM
Thanks for your prompt response,
I have to do this task in Prolog there is no way around it plus I have to use files as it wouldnt be feasible adding to the program in execution as huge amounts of data exist in the patterns file. Currently whats happening is a new user file is created (not a pl file though for some reason). This file is populated massively with all the patterns and endless lines saying 'end of file'.
Also in the user file the variables from the pattern file don't translate e.g. the variables appear like '_G699', '_G1060', etc.
Any help appreciated or suggestions
I have to do this task in Prolog there is no way around it plus I have to use files as it wouldnt be feasible adding to the program in execution as huge amounts of data exist in the patterns file. Currently whats happening is a new user file is created (not a pl file though for some reason). This file is populated massively with all the patterns and endless lines saying 'end of file'.
Also in the user file the variables from the pattern file don't translate e.g. the variables appear like '_G699', '_G1060', etc.
Any help appreciated or suggestions
#4
Posted 08 March 2007 - 10:22 PM
Quote
I have to do this task in Prolog there is no way around it...
I'm curious - why is there no way around it?
Imagine.
#5
Posted 09 March 2007 - 09:33 AM
Possibly because it's a homework task? I remember that the new Forum Policies disrespect such questions...
#6
Posted 09 March 2007 - 11:46 AM
its not homework, I realise this question is complex.
A simpler question I have is how can one overcome an error 'Redefined static procedure'.
I know why its happening because I am using two files with the same predicate. Is there a functional way of being able to use the predicates simultaneously? i.e. What procedures would be best e.g. consult, load_file, ensure_loaded.
Any help appreciated
A simpler question I have is how can one overcome an error 'Redefined static procedure'.
I know why its happening because I am using two files with the same predicate. Is there a functional way of being able to use the predicates simultaneously? i.e. What procedures would be best e.g. consult, load_file, ensure_loaded.
Any help appreciated
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


This topic is locked









