Data Structures and Types 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 Data Structures and Types flashcards as text
Which operator decomposes a compound term into a list `[Functor | Args]` in Picat?
Answer: =.. (the univ operator)
The `=..` (univ) operator decomposes `f(a,b)` into `[f, a, b]` and can also construct terms from such lists.
What does `f(a, b, c) =.. L` bind L to in Picat?
Answer: [f, a, b, c]
The univ operator produces a list whose head is the functor and whose tail is the argument list: `[f, a, b, c]`.
What does `arg(1, point(3, 4), X)` bind X to in Picat?
Answer: 3
`arg/3` is 1-indexed in Picat: arg 1 of `point(3,4)` is `3`, the first argument.
Which predicate extracts the functor name and arity from a compound term?
Answer: functor(T, F, A)
`functor(T, F, A)` binds F to the principal functor of T and A to its arity.
What does `compound(hello)` evaluate to in Picat?
Answer: false
`compound/1` fails for atoms like `hello` — a compound term must have a functor and at least one argument.
What does `copy_term(f(X, X), Copy)` produce in Picat?
Answer: Copy = f(_A, _A) with a single new shared variable
`copy_term/2` creates a renamed copy: both positions of X become the same new variable _A, preserving sharing.
What is the arity of the Picat term `foo(a)`?
Answer: 1
Arity is the number of arguments a compound term takes; `foo(a)` has exactly one argument, so its arity is 1.