โ† 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. In a Picat `if-then-else` expression, what is required if the else branch is omitted?

    Answer: Omitting else is a syntax error in function mode

    In Picat's functional/imperative mode, if without else is a syntax error; both branches must be present.

  2. How are multi-dimensional arrays indexed in Picat?

    Answer: A[I,J]

    Picat uses comma-separated indices inside a single bracket pair, e.g., A[I,J], for multi-dimensional array access.

  3. What built-in predicate fills an array with a default value in Picat?

    Answer: There is no fill built-in; use a foreach loop to initialize

    Picat allocates arrays with new_array but does not have a fill built-in; initialization requires iterating and assigning each element.

  4. Which statement about `return` in a Picat function is correct?

    Answer: return Expr exits the function with value Expr

    Picat supports the return Expr statement to exit a function early and produce a return value.

  5. In Picat, how is standard output written from an imperative function?

    Answer: Both print(X) and printf(Fmt,Args) are valid

    Picat provides both print/println for simple output and printf/writef for formatted output in imperative functions.

  6. What does `new_array(5)` produce in Picat?

    Answer: A 1-D array of size 5 with uninitialized (free) elements

    new_array(5) creates a one-dimensional array of 5 elements, each an unbound (free) variable.

  7. How do you iterate over both index and value of a list in a Picat `foreach` loop?

    Answer: foreach(I in 1..List.len, V = List[I])

    The standard idiom is to iterate over an index range and access List[I], since foreach over a list gives values only.