← All Picat Flashcard Decks

Mixed Deck — All Picat Topics Flashcards

100 cards from real Picat practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.

Read the first 20 Mixed Deck — All Picat Topics flashcards as text
  1. How do you declare a local variable inside a Picat imperative function?

    Answer: No declaration needed; first assignment creates it

    In Picat, variables do not need explicit declarations; the first assignment in a scope implicitly introduces them.

  2. What does Picat's `to_string/1` function do that a predicate could not directly accomplish?

    Answer: It returns a string value usable inline in expressions like `print(to_string(42) ++ "!")`

    As a function, `to_string/1` returns a value immediately composable with operators like `++`.

  3. What is the occurs check, and does Picat's default unification perform it?

    Answer: Prevents binding X to a term containing X to avoid circular structures; no, not by default

    The occurs check prevents creating circular (infinite) terms by checking X ∉ T before X=T, but Picat (like most Prolog-family systems) skips it by default for performance.

  4. She had a *relentlessly* positive attitude.

    Answer: Tireless

    'Relentlessly' means in an unceasingly intense or harsh way. When applied to a positive attitude, it suggests an attitude that never gives up or diminishes. 'Tireless' perfectly captures this meaning, implying an attitude that persists without becoming weary or exhausted.

  5. Consider the following Picat code. What value will be printed to the console? main => S = 0, foreach (X in [10, 5, 3]) S := S + X end, println(S).

    Answer: 18

    The `foreach` loop iterates through each element of the list `[10, 5, 3]`. The variable `S` is initialized to 0. In each iteration, the current element `X` is added to `S`. The calculation proceeds as: `0 + 10 = 10`, then `10 + 5 = 15`, and finally `15 + 3 = 18`. The final value, 18, is printed.

  6. In Picat CP, what does posting `X #>= Y # B` accomplish (assuming B is a 0/1 variable)?

    Answer: It sets B to 1 if X >= Y, and to 0 otherwise

    The `#` operator creates a reified constraint, making B equal 1 exactly when the constraint X #>= Y is satisfied.

  7. How do you convert the string "42" to the integer 42 in Picat?

    Answer: to_integer("42")

    `to_integer/1` is Picat's built-in for converting strings and other terms to integer values.

  8. The word VALIDATE most nearly means:

    Answer: confirm

    Validate means to demonstrate or support the truth or value of something; to confirm.

  9. Which labeling option in Picat's CP `solve` tells the solver to choose the variable with the smallest remaining domain first?

    Answer: [ff]

    `ff` (fail-first) selects the variable with the fewest remaining domain values, reducing early branching failures.

  10. Consider the following Picat code: `process_data($point(A, B), Result) => Result = A + B. process_data([H|_], Result) => Result = H.` What happens when the query `process_data(Data, R)` is called if `Data` is the structure `$point(5, 10)`?

    Answer: The first rule is chosen through pattern matching, and R is unified with 15.

    Picat's engine will try to match the call `process_data($point(5, 10), R)` with the defined rule heads. The structure `$point(5, 10)` matches the pattern `$point(A, B)`. This is a successful one-sided unification where A gets the value 5 and B gets the value 10 for the scope of the rule. The body `Result = A + B` is then executed, unifying `Result` with `5 + 10`, which is 15.

  11. What distinguishes a Picat `function` (using = in the head) from a `predicate`?

    Answer: A function must return exactly one value via the last argument position, while a predicate succeeds or fails

    In Picat, a function definition uses `f(Args) = Value => Body`, returning a deterministic value, whereas a predicate succeeds or fails without an explicit return.

  12. Which `util` module predicate removes duplicate elements from a list while preserving order?

    Answer: remove_dups/2

    `remove_dups/2` removes duplicate elements from the list while keeping the first occurrence of each element.

  13. What does [X : X in [a,b,c,d,e], X \= b, X \= d] produce in Picat?

    Answer: [a, c, e]

    The two inequality conditions X \= b and X \= d both use structural non-unification, excluding the atoms b and d and leaving [a, c, e].

  14. In Picat's CP module, which predicate is used to declare a list of decision variables with a shared domain?

    Answer: Vars :: [Low..High]

    The `::` operator with a list on the left and a domain expression on the right constrains all variables in the list to that domain.

  15. Which of the following statements about Picat's tabling mechanism is FALSE?

    Answer: It requires manual cache invalidation using a special built-in predicate.

    Picat's tabling is largely automatic. Once a predicate is declared with `table`, the system manages the storage and retrieval of answers without requiring the programmer to manually invalidate or clear the cache during normal execution. While there is a built-in `initialize_table` to clear all tables, it's for resetting the state, not for manual cache invalidation as part of the core logic. The other statements are true: tabling applies to both predicates and functions, uses a linear tabling mechanism, and is enabled with the `table` keyword before the rules.

  16. Can a Picat `action/4` clause have a Cost of 0?

    Answer: Yes, zero-cost actions are allowed and represent free transitions

    Zero is a valid non-negative cost; zero-cost actions are treated as free moves that do not increase the accumulated plan cost.

  17. A programmer wants to handle lists, with a special case for lists starting with the atom 'a'. What is the result of the query `handle_list([a,b,c], Res)` with the following predicate definitions? ```picat handle_list(L, general) => length(L) > 0. handle_list([a|_], specific_a). handle_list([], empty). ```

    Answer: general

    Picat attempts to match predicate rules from top to bottom. The goal `handle_list([a,b,c], Res)` first attempts to match `handle_list(L, general)`. This match succeeds, binding `L` to `[a,b,c]`. The guard `length(L) > 0` is then checked and succeeds. `Res` is bound to `general` and the call succeeds immediately. The second, more specific rule is never tried because a successful match was already found.

  18. What does `string_codes("ab", Cs)` bind Cs to in Picat?

    Answer: [97, 98]

    `string_codes/2` converts a string to a list of Unicode code points; 97 = 'a' and 98 = 'b'.

  19. How are strings internally represented in Picat?

    Answer: As lists of character codes

    Strings in Picat are represented as lists of character codes (integers), similar to traditional Prolog.

  20. In Picat, what type does the literal `"hello"` (double-quoted) have?

    Answer: String — its own distinct type

    In Picat, double-quoted literals are of the `string` type, which is distinct from atoms and lists.