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
Which syntax correctly defines a Picat function that returns the square of X?
Answer: square(X) = X * X
Picat functions are defined with `=` between the head and the return expression.
In Picat, what happens when you call a function but no clause pattern matches the arguments?
Answer: An existence error or pattern-match failure is thrown
If no function clause matches, Picat raises an exception because functions must return a value.
A Picat predicate clause uses `?=>` instead of `=>`. What does this indicate?
Answer: The predicate is nondeterministic and may leave choice points
`?=>` marks a nondeterministic clause that keeps a choice point, allowing backtracking.
Can a Picat function be embedded directly inside an arithmetic expression such as `Y = f(X) + 3`?
Answer: Yes, because functions return values usable in expressions
Picat functions return values and can appear anywhere an expression is expected.
Which of the following is a valid way to call a Picat predicate `greet(Name)`?
Answer: greet("Alice")
Predicates are called as statements; they do not return values and cannot appear inside expressions.
In Picat, the body of a function clause and the body of a predicate clause share which feature?
Answer: Both can include goals, assignments, and conditionals
Both function and predicate bodies are sequences of goals and can use the same control constructs.
What is the correct way to define a recursive Picat function `fact(N)` for the factorial of N?
Answer: fact(0) = 1. fact(N) = N * fact(N-1).
Recursive Picat functions use `=` and pattern-match across multiple clauses.