Picat General 5 — Questions and Answers
Question 1: Which Picat module should you import to use SAT-based constraint solving instead of CP propagation?
- sat (Correct answer)
- cp
- smt
- boolean
Correct answer: sat
Picat's `sat` module encodes finite-domain constraints as propositional SAT clauses and calls a built-in SAT solver, offering an alternative to the `cp` propagation engine.
Question 2: What does `bp.pred_name(Args)` syntax allow in Picat?
- Calling a B-Prolog built-in predicate not natively exposed in Picat (Correct answer)
- Bypassing type checking for performance
- Calling a C foreign function
- Accessing a byte-code primitive
Correct answer: Calling a B-Prolog built-in predicate not natively exposed in Picat
The `bp.` prefix lets Picat code call B-Prolog predicates directly, since Picat is built on the B-Prolog engine and exposes its built-ins this way.
Question 3: In Picat, what does the `foreach` loop construct do?
- Iterates over a list or range, executing a goal for each element without building a return value (Correct answer)
- Collects results into a new list like map
- Filters elements satisfying a condition
- Applies a constraint to each variable in a list
Correct answer: Iterates over a list or range, executing a goal for each element without building a return value
`foreach(E in List, Goal)` executes Goal for each element E in List purely for side effects, analogous to a for-each loop in imperative languages.
Question 4: What value does `max_list([3,1,4,1,5,9])` return in Picat?
- 9 (Correct answer)
- 5
- 3
- 1
Correct answer: 9
`max_list/1` returns the largest element of the list, which is 9 in this case.
Question 5: Which Picat feature allows a predicate to be both used for generation and for checking without separate clauses?
- Unification-based pattern matching with backtracking (Correct answer)
- Overloaded operators
- Macro expansion
- Type inference
Correct answer: Unification-based pattern matching with backtracking
Because Picat predicates use unification and backtracking, the same clause can generate solutions when arguments are unbound and verify correctness when arguments are ground.
Question 6: What is the correct way to concatenate two strings in Picat?
- S = S1 ++ S2 (Correct answer)
- S = concat(S1, S2)
- append(S1, S2, S)
- S = S1 + S2
Correct answer: S = S1 ++ S2
The `++` operator concatenates two strings (or lists) in Picat, returning a new string that is their combination.
Question 7: When a Picat program uses `cl` (command-line) mode, how is the entry point defined?
- A predicate named `main` with arity 0 or 1 is called automatically (Correct answer)
- A special `start` function must be exported
- The first predicate in the file is called
- You pass the predicate name as a command-line flag
Correct answer: A predicate named `main` with arity 0 or 1 is called automatically
When running a Picat script from the command line, the runtime automatically calls the `main/0` or `main/1` predicate (with command-line arguments as a list) as the entry point.
Which Picat module should you import to use SAT-based constraint solving instead of CP propagation?