Różnice
Różnice między wybraną wersją a wersją aktualną.
|
|
pl:prolog:pllib:file_operations [2019/06/27 15:50] |
pl:prolog:pllib:file_operations [2019/06/27 15:50] (aktualna) |
| ====== File operations ====== |
| {{tag>patterns read/write}} |
| ===== Description ===== |
| Simple program to file operations |
| |
| **Source**: PrologTutorial (on-line tutorial) |
| ===== Download ===== |
| Program source code: {{file_operations.pl}} |
| ===== Listing ===== |
| <code prolog> |
| /* prolog tutorial 2.10 */ |
| |
| browse :- |
| seeing(Old), /* save for later */ |
| see(user), |
| write('Enter name of file to browse: '), read(File), |
| see(File), /* open this file */ |
| repeat, |
| read(Data), /* read from File */ |
| process(Data), |
| seen, /* close File */ |
| see(Old), /* previous read source */ |
| !. /* stop now */ |
| |
| process(end_of_file) :- !. |
| process(Data) :- write(Data), write('.'), nl, fail. |
| |
| |
| my_save(ToFile) :- |
| telling(Old), /* current write output */ |
| tell(ToFile), /* open this file */ |
| listing, /* list all clauses in memory */ |
| told, /* close ToFile */ |
| tell(Old). /* resume this output */ </code> |
| ===== Comments ===== |
| |