Picat Using Standard Modules 5 — Questions and Answers
Question 1: Which predicate from the `lists` module appends two lists?
- concat/3
- join/3
- append/3 (Correct answer)
- merge/3
Correct answer: append/3
`append/3` unifies the third argument with the concatenation of the first two list arguments.
Question 2: In the Picat `io` module, what does `writef/2` do?
- Writes formatted output using a format string (Correct answer)
- Writes a list of terms to a file
- Writes with full quoting enabled
- Writes a float with fixed precision
Correct answer: Writes formatted output using a format string
`writef/2` takes a format string and a list of arguments, printing formatted output similar to `printf`.
Question 3: What does `maps:keys(Map)` return?
- A sorted list of all keys in Map (Correct answer)
- The number of key-value pairs in Map
- A list of all values in Map
- A boolean indicating if Map has any keys
Correct answer: A sorted list of all keys in Map
`maps:keys/1` returns a sorted list containing all the keys currently stored in the map.
Question 4: Which `util` module predicate removes duplicate elements from a list while preserving order?
- unique/2
- remove_dups/2 (Correct answer)
- dedupe/2
- list_to_set/2
Correct answer: remove_dups/2
`remove_dups/2` removes duplicate elements from the list while keeping the first occurrence of each element.
Question 5: In Picat, the `sat` module is used primarily for what purpose?
- String matching and tokenization
- Satisfiability solving over Boolean variables (Correct answer)
- Statistical analysis of datasets
- Secure authentication tokens
Correct answer: Satisfiability solving over Boolean variables
The `sat` module provides a SAT (Boolean satisfiability) solver that can handle Boolean constraints efficiently.
Question 6: What does `lists:nth/3` do in Picat?
- Returns the Nth element of a list (1-based) (Correct answer)
- Returns the last N elements
- Splits a list at position N
- Counts the number of elements equal to N
Correct answer: Returns the Nth element of a list (1-based)
`nth/3` retrieves the element at a 1-based index N from a list, binding the third argument to that element.
Question 7: Which `math` module predicate computes the ceiling of a floating-point number?
- ceiling/1 (Correct answer)
- ceil/1
- round_up/1
- floor_add/1
Correct answer: ceiling/1
`ceiling/1` returns the smallest integer greater than or equal to the given floating-point number.
Which predicate from the `lists` module appends two lists?