โ† All Picat Flashcard Decks

Pattern Matching Rules 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 Pattern Matching Rules flashcards as text
  1. In Picat, what is the difference between `==` and `=` when used in a rule body?

    Answer: `==` tests strict equality without binding; `=` performs unification which may bind variables

    `==` checks that two terms are identical without unifying them, while `=` attempts unification and may bind uninstantiated variables.

  2. A Picat rule written as `len([], Acc, Acc) => true.` is an example of what pattern technique?

    Answer: Using an accumulator argument that matches when the base case (empty list) is reached

    The pattern matches the empty list `[]` as the first argument and uses the same variable `Acc` twice to assert the accumulator equals the result at the base case.

  3. What does Picat do when a deterministic rule (`=>`) pattern matches but its body fails?

    Answer: It throws an error and does NOT try other clauses

    Once a deterministic (`=>`) rule's head matches, Picat commits; body failure propagates as an exception rather than triggering backtracking.

  4. Which Picat pattern would match a struct term `point(X, Y)` only when both coordinates are integers?

    Answer: point(X, Y), integer(X), integer(Y) => ...

    Picat uses guard conditions to further restrict matches; `integer(X)` and `integer(Y)` in the guard enforce the type constraint.

  5. In Picat, what is the outcome of `[1,2|T] = [1,2,3,4]`?

    Answer: T = [3,4]

    The pattern `[1,2|T]` matches a list starting with 1 and 2; T binds to the remaining tail `[3,4]`.

  6. When writing recursive list-processing predicates in Picat, which pair of clause heads handles both the base and recursive cases?

    Answer: One clause with `[]` and one with `[H|T]`

    The standard structural recursion pattern uses `[]` for the empty-list base case and `[H|T]` for the non-empty recursive case.

  7. In Picat, what does it mean for a pattern match to 'unify' with a compound term?

    Answer: The functor names and arities must match, and each corresponding argument must recursively unify

    Unification of compound terms requires matching functor and arity, then recursively unifying each argument position pairwise.