← All Picat Flashcard Decks

General Flashcards

7 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 7 General flashcards as text
  1. What is a 'guard' in a Picat rule, and where does it appear?

    Answer: A boolean condition placed between the head and => that must hold for the rule to fire

    A guard is an optional boolean test in the rule head, written before `=>`, that refines when a particular clause applies.

  2. Which Picat predicate retrieves all solutions of a goal as a list?

    Answer: findall(Template, Goal, List)

    `findall/3` collects every Template instantiation for which Goal succeeds into List, returning [] if Goal always fails.

  3. In Picat, what does the `@` symbol signify when used in a term like `[H|T]@List`?

    Answer: It aliases the whole list to List while also destructuring

    Picat supports as-patterns with `@`, so `[H|T]@List` matches a non-empty list, binding H to the head, T to the tail, and List to the entire structure simultaneously.

  4. 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.

  5. Which constraint in Picat's `cp` module ensures all variables in a list take distinct values?

    Answer: all_different(Vars)

    `all_different/1` posts a global constraint requiring every variable in the list to be assigned a different value.

  6. How does Picat handle arithmetic evaluation — must you use a special operator?

    Answer: Yes, use X = Y evaluates; without it, expressions remain unevaluated terms

    In Picat, `X = Expr` evaluates arithmetic when Expr contains numeric operations, but unlike Prolog you do not need a separate `is` operator — the = operator evaluates arithmetic expressions automatically.

  7. What is the purpose of the `table(+, +, min)` mode declaration in Picat?

    Answer: It memoizes the predicate, keeping only the answer with the minimum value for the last argument

    Mode declarations like `table(+,+,min)` instruct the tabling engine to retain only the optimal (minimum) tabled result for each input combination, enabling dynamic-programming optimizations.