Picat Picat String and I/O Operations 2 — Questions and Answers
Question 1: Which built-in opens a file for writing in Picat?
- open(File, write, Stream) (Correct answer)
- fopen(File, "w")
- file_open(File, write)
- write_file(File)
Correct answer: open(File, write, Stream)
`open(File, write, Stream)` opens a file for writing and binds the resulting stream to Stream.
Question 2: What predicate writes a term followed by a newline to standard output in Picat?
- writeln(T) (Correct answer)
- println(T)
- print_line(T)
- write_nl(T)
Correct answer: writeln(T)
`writeln(T)` writes term T to standard output and appends a newline character.
Question 3: How do you close a file stream after I/O operations in Picat?
- fclose(Stream)
- stream_close(Stream)
- close(Stream) (Correct answer)
- end_stream(Stream)
Correct answer: close(Stream)
`close(Stream)` closes an open file stream, freeing the associated resources.
Question 4: Which format specifier prints an integer inside Picat's `format` predicate?
- %d
- %i
- ~d (Correct answer)
- {d}
Correct answer: ~d
Picat's `format` predicate uses `~d` to print an integer argument.
Question 5: What does `read_term(Stream, Term, Options)` accomplish in Picat?
- Reads and parses a Picat term from a stream (Correct answer)
- Reads a CSV record from a file
- Reads raw bytes into a list
- Reads the next whitespace-delimited word
Correct answer: Reads and parses a Picat term from a stream
`read_term/3` reads and parses a complete Picat term from the given stream using the provided options.
Question 6: Which predicate forces buffered output to be written to a stream immediately in Picat?
- flush_buffer()
- flush_output(Stream) (Correct answer)
- sync(Stream)
- force_write(Stream)
Correct answer: flush_output(Stream)
`flush_output(Stream)` forces any buffered output to be physically written to the stream.
Which built-in opens a file for writing in Picat?