PDA

View Full Version : Reading input from files PROLOG


ruman29
03-08-2007, 08:40 AM
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.

Reedbeta
03-08-2007, 09:09 AM
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.

ruman29
03-08-2007, 11:49 AM
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

donBerto
03-08-2007, 02:22 PM
I have to do this task in Prolog there is no way around it...


I'm curious - why is there no way around it?

pater
03-09-2007, 01:33 AM
Possibly because it's a homework task? I remember that the new Forum Policies disrespect such questions...

ruman29
03-09-2007, 03: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