Picat Using Standard Modules 3 — Questions and Answers
Question 1: What is the correct way to open a file for writing in Picat using the `io` module?
- open(File, write, Stream) (Correct answer)
- io.open(File, write)
- fopen(File, "w")
- new_file(File, Stream)
Correct answer: open(File, write, Stream)
`open/3` takes the filename, mode atom (`write`, `read`, or `append`), and binds a stream variable.
Question 2: Which `sets` module predicate computes the union of two sets represented as sorted lists?
- union/3 (Correct answer)
- set_union/3
- merge/3
- append/3
Correct answer: union/3
`union/3` in the `sets` module takes two sorted lists and produces their union as a sorted list.
Question 3: In Picat's `math` module, which predicate computes the base-10 logarithm?
- ln/1
- log/1
- log10/1 (Correct answer)
- lg/1
Correct answer: log10/1
`log10/1` computes the base-10 (common) logarithm, while `log/1` computes the natural logarithm.
Question 4: Which `string` module function splits a string by a delimiter character?
- split/2 (Correct answer)
- tokenize/2
- explode/2
- partition/2
Correct answer: split/2
`split/2` takes a string and a delimiter string, returning a list of substrings.
Question 5: What does `:- import lists, sets.` accomplish in a Picat file?
- Imports only the `lists` module
- Fails because you can't import two modules at once
- Imports both the `lists` and `sets` modules (Correct answer)
- Creates a new combined module
Correct answer: Imports both the `lists` and `sets` modules
Multiple modules can be imported in a single `:- import` directive by separating them with commas.
Question 6: In the Picat `maps` module, which predicate creates a new empty map?
- maps:empty/1
- new_map/1 (Correct answer)
- maps:new/1
- {}
Correct answer: new_map/1
`new_map/1` binds a variable to a fresh, empty map data structure in Picat.
Question 7: Which `util` module function returns the minimum value in a list?
- min/1
- min_list/1 (Correct answer)
- least/1
- first_sorted/1
Correct answer: min_list/1
`min_list/1` returns the smallest element of a numerical list, symmetric to `max_list/1`.
What is the correct way to open a file for writing in Picat using the `io` module?