Input/Output and File Operations
OUTPUT
- [pp ...] (pretty-print)
Displays all the parameters exactly as they are.
Texts will have quotation marks. Variables will be numbered from 0 upwards.
Numbers, lists, pairs, everything will look exactly as it would look in the code.
- [write ...]
The main output instruction. Displays parameters as follows:
- Neither symbols nor floating-point numbers are displayed.
- Texts are displayed without quotations.
- Integer numbers are displayed as ASCII characters.
- Lists of parameters are displayed as if using pp instruction. Therefore [write [1 2 3]] will display 123.
- [nl] - moves to the next line (newline).
- [show ...]
Convenient macrodefinition. Check [list show] to see the full implementation.
- Texts are displayed using write (without quotation marks).
- All other parameters are dispalyed using pp.
- Newline appears at the end.
INPUT
- [pr ...] (pretty-read)
Reads Prolog element from the console. At least, tries.
- [read ...]
Skips control and newline characters, then reads line of characters (until ENTER).
- [readln ...]
Reads line of characters (until ENTER). Usefull if you type the input in the same line as the instruction during interactive session.
FILE OUTPUT
- [file_writer file "file_name"]
Opens file specified by "file_name" for writing. If file doesn't exist then it is created.
Newly opened fileis ready for writing using the file symbol as if it was a write instruction.
If file is a variable, then a new anonymous symbols is created.
Once this symbol is garbage-collected, the associated file is closed.
- [file ...]
Works exactly as write but the output is written to the file instead.
The file symbol must be associated with a physical file before use, as described above.
- [file] (without parameters) - closes the file.
- EXAMPLE 1: Creating a file called "some_file.txt" and writing "Hello World" with newline into it.
- [create_atom "file"]
- [file_writer file "some_file.txt"]
- [file "Hello World\n"]
- [file]
- EXAMPLE 2: Same as above but with implicit file closing by garbage collector.
- [res [file_writer *file "some_file.txt"] [*file "Hello World\n"]]
FILE INPUT
- [file_reader file "file_name"]
Opens file specified by "file_name" for reading. If the file doesn't exists then file_reader fails.
If file is a variable, then an anonymous symbol is created. Once this symbols is garbage-collected, the associated file is closed.
- [file ...]
Works exactly as pr but read the data from the file.
It also has got a two parameter variant.
The precise behaviour is:
- [file *x] - same as pr.
- [file "line" *x] - reads line of text (until newline).
- [file "abcde..and-so-on" *x] - skips characters not included and then read as many characters as in the specified string.
For example: "abcdefghijklmnopqrstuvwxyz" would read only a lower-case string.
- [file] (without parameters) - closes the file.
PROGRAM LOADERS
- [load "module_name.prc"] - loads specified module. If module is already loaded then it gets re-loaded.
- [consult "module_name.prc"] - same as load but displays the content of the loaded module on the console.
- [import "module_name.prc"] - loads specified module only if it is not already loaded.
- [batch "file_name"] - executes specified file as if it was a stored interactive session.
The last instruction inside such a file should be [exit].