← All Picat Flashcard Decks

Mixed Deck — All Picat Topics Flashcards

100 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 20 Mixed Deck — All Picat Topics flashcards as text
  1. How do you declare a local variable inside a Picat imperative function?

    Answer: No declaration needed; first assignment creates it

    In Picat, variables do not need explicit declarations; the first assignment in a scope implicitly introduces them.

  2. What is the occurs check, and does Picat's default unification perform it?

    Answer: Prevents binding X to a term containing X to avoid circular structures; no, not by default

    The occurs check prevents creating circular (infinite) terms by checking X ∉ T before X=T, but Picat (like most Prolog-family systems) skips it by default for performance.

  3. She had a *relentlessly* positive attitude.

    Answer: Tireless

    'Relentlessly' means in an unceasingly intense or harsh way. When applied to a positive attitude, it suggests an attitude that never gives up or diminishes. 'Tireless' perfectly captures this meaning, implying an attitude that persists without becoming weary or exhausted.

  4. Consider the following Picat code. What value will be printed to the console? main => S = 0, foreach (X in [10, 5, 3]) S := S + X end, println(S).

    Answer: 18

    The `foreach` loop iterates through each element of the list `[10, 5, 3]`. The variable `S` is initialized to 0. In each iteration, the current element `X` is added to `S`. The calculation proceeds as: `0 + 10 = 10`, then `10 + 5 = 15`, and finally `15 + 3 = 18`. The final value, 18, is printed.

  5. How do you convert the string "42" to the integer 42 in Picat?

    Answer: to_integer("42")

    `to_integer/1` is Picat's built-in for converting strings and other terms to integer values.

  6. Which labeling option in Picat's CP `solve` tells the solver to choose the variable with the smallest remaining domain first?

    Answer: [ff]

    `ff` (fail-first) selects the variable with the fewest remaining domain values, reducing early branching failures.

  7. Consider the following Picat code: `process_data($point(A, B), Result) => Result = A + B. process_data([H|_], Result) => Result = H.` What happens when the query `process_data(Data, R)` is called if `Data` is the structure `$point(5, 10)`?

    Answer: The first rule is chosen through pattern matching, and R is unified with 15.

    Picat's engine will try to match the call `process_data($point(5, 10), R)` with the defined rule heads. The structure `$point(5, 10)` matches the pattern `$point(A, B)`. This is a successful one-sided unification where A gets the value 5 and B gets the value 10 for the scope of the rule. The body `Result = A + B` is then executed, unifying `Result` with `5 + 10`, which is 15.

  8. In Picat's CP module, which predicate is used to declare a list of decision variables with a shared domain?

    Answer: Vars :: [Low..High]

    The `::` operator with a list on the left and a domain expression on the right constrains all variables in the list to that domain.

  9. Which of the following statements about Picat's tabling mechanism is FALSE?

    Answer: It requires manual cache invalidation using a special built-in predicate.

    Picat's tabling is largely automatic. Once a predicate is declared with `table`, the system manages the storage and retrieval of answers without requiring the programmer to manually invalidate or clear the cache during normal execution. While there is a built-in `initialize_table` to clear all tables, it's for resetting the state, not for manual cache invalidation as part of the core logic. The other statements are true: tabling applies to both predicates and functions, uses a linear tabling mechanism, and is enabled with the `table` keyword before the rules.

  10. A programmer wants to handle lists, with a special case for lists starting with the atom 'a'. What is the result of the query `handle_list([a,b,c], Res)` with the following predicate definitions? ```picat handle_list(L, general) => length(L) > 0. handle_list([a|_], specific_a). handle_list([], empty). ```

    Answer: general

    Picat attempts to match predicate rules from top to bottom. The goal `handle_list([a,b,c], Res)` first attempts to match `handle_list(L, general)`. This match succeeds, binding `L` to `[a,b,c]`. The guard `length(L) > 0` is then checked and succeeds. `Res` is bound to `general` and the call succeeds immediately. The second, more specific rule is never tried because a successful match was already found.

  11. What does `string_codes("ab", Cs)` bind Cs to in Picat?

    Answer: [97, 98]

    `string_codes/2` converts a string to a list of Unicode code points; 97 = 'a' and 98 = 'b'.

  12. How are strings internally represented in Picat?

    Answer: As lists of character codes

    Strings in Picat are represented as lists of character codes (integers), similar to traditional Prolog.

  13. In Picat, what type does the literal `"hello"` (double-quoted) have?

    Answer: String — its own distinct type

    In Picat, double-quoted literals are of the `string` type, which is distinct from atoms and lists.

  14. What is the correct syntax to access element at index 2 of array A in Picat?

    Answer: A[2]

    Picat arrays use bracket notation `A[I]` for indexed access, with indexing starting at 1.

  15. What will be the result of the following Picat query? `go => X = 1, Y = X, $f(X, 2) = $f(1, Y), println(X), println(Y).`

    Answer: It will print 1 and then 1.

    The query first binds X to 1. Then Y is unified with X, so Y is also 1. The unification `$f(X, 2) = $f(1, Y)` succeeds because at this point, it is equivalent to `$f(1, 2) = $f(1, 1)`, which successfully unifies Y to be 2, but since X is already bound to 1 and Y is bound to X, Y becomes 1. The unification `$f(1,2) = $f(1,1)` will succeed, and the final values of X and Y will both be 1. The `println` calls will therefore print 1 and 1.

  16. What is the approximate speed of light in a vacuum?

    Answer: 300,000 km/s

    Light travels at approximately 300,000 kilometers per second (about 186,000 miles per second) in a vacuum.

  17. Which Picat operator is used to check structural equality without performing unification?

    Answer: ==

    The == operator tests if two terms are identical in structure and variable bindings without unifying them.

  18. What is the output of the following Picat code snippet? main => Counter = 4, Result = 1, while (Counter > 1) Result := Result * Counter, Counter := Counter - 1 end, println(Result).

    Answer: 24

    The `while` loop initializes `Result` to 1 and `Counter` to 4. The loop continues as long as `Counter` is greater than 1. The loop executes for `Counter` values of 4, 3, and 2. The `Result` is updated as follows: `1 * 4 = 4`, then `4 * 3 = 12`, then `12 * 2 = 24`. When `Counter` becomes 1, the loop condition is false and it terminates, printing the final value of `Result`.

  19. What does `to_array([a, b, c])` return in Picat?

    Answer: {a, b, c}

    `to_array/1` converts a list to a Picat array represented with curly-brace notation `{a, b, c}`.

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

Written and edited by , founder of Practice Test Geeks, with AI assistance. Exam facts are checked against the official sources linked below. Editorial policy

Sources & references

Exam facts on this page (fees, format, dates, passing scores) are checked against these official sources; the date is our last check. Editorial policy

  1. officialasvab.com — Test delivery, eligibility, registration deadline, retake policy, score release, time limit, score validity, exam information · verified Dec 2026