โ† All Picat Flashcard Decks

Functions vs. Predicates 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 Functions vs. Predicates flashcards as text
  1. In Picat, which operator separates the head from the body in a deterministic predicate clause?

    Answer: =>

    `=>` is the neck operator for a deterministic predicate clause in Picat.

  2. Consider `len([]) = 0` and `len([_|T]) = 1 + len(T)`. Why must `len` be a function rather than a predicate here?

    Answer: Because it produces a return value used in an arithmetic expression

    The result of `len` is used directly in `1 + len(T)`, requiring it to be a function that yields a value.

  3. Which statement about Picat functions is FALSE?

    Answer: A function can be nondeterministic by using `?=`

    Picat does not have a `?=` nondeterministic function neck; functions are deterministic constructs.

  4. A Picat predicate `max_list(List, Max)` binds `Max` to the largest element. How is this different from a function approach?

    Answer: The predicate unifies the result via an extra output argument instead of returning it

    Predicates communicate results through extra arguments bound by unification, not through a return value.

  5. Given `double(X) = 2 * X`, what does `Y = double(5) + double(3)` evaluate to?

    Answer: Y = 16

    `double(5)` returns 10 and `double(3)` returns 6, so `Y = 16`.

  6. In Picat, a function clause with a guard looks like `f(X) = V, Guard => Body`. When is `Guard` evaluated?

    Answer: After the head matches but before executing the body or committing to the return expression

    The guard is checked after the head pattern matches; if it fails, the next clause is tried.

  7. Which built-in feature of Picat allows a predicate to behave like a function when exactly one solution is needed?

    Answer: `once(Goal)`

    `once/1` commits to the first solution of a nondeterministic predicate, discarding remaining choice points.

Functions vs. Predicates Flashcards โ€” Picat Study Cards with Answers