โ† All Picat Flashcard Decks

Imperative Programming Constructs 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 Imperative Programming Constructs flashcards as text
  1. Which Picat construct is used to handle runtime exceptions in imperative code?

    Answer: try ... catch ... end

    Picat uses try ... catch(Pattern) ... end blocks to intercept and handle exceptions.

  2. What does `string_to_atom(S)` do when used in a Picat imperative function?

    Answer: Converts a string (char list) to an atom

    string_to_atom/1 converts a Picat string (list of character codes or chars) into an atom.

  3. How do you concatenate two lists in Picat within an imperative function?

    Answer: L1 ++ L2

    The ++ operator performs list concatenation in Picat, returning a new combined list.

  4. In Picat's imperative mode, what does `X @= Y` mean?

    Answer: X is assigned the value of Y only if X is unbound

    The @= operator in Picat assigns Y to X only when X is an unbound (free) variable, leaving it unchanged otherwise.

  5. What is the output of the Picat code: `X := 3, (X > 2 -> Y := "big" ; Y := "small"), print(Y)`?

    Answer: big

    Since X is 3 which is greater than 2, the then-branch executes and Y is assigned "big", which is then printed.

  6. In Picat, which of the following correctly swaps the values of two mutable variables A and B?

    Answer: Tmp := A, A := B, B := Tmp

    A temporary variable must hold one value during the swap; the naive two-step assignment would lose A's original value.

  7. What does a `foreach` loop do when given an empty list in Picat?

    Answer: Skips the body entirely and continues normally

    Iterating over an empty list with foreach simply skips the loop body; this is the standard and expected behavior.