Picat Using Standard Modules 2 — Questions and Answers
Question 1: Which Picat module provides the `sort/1` and `msort/1` predicates for list sorting?
- lists (Correct answer)
- util
- basic
- sets
Correct answer: lists
The `lists` module provides `sort/1` (removes duplicates) and `msort/1` (keeps duplicates) for sorting lists.
Question 2: In the Picat `math` module, what does `gcd(12, 8)` return?
- 2
- 4 (Correct answer)
- 6
- 8
Correct answer: 4
`gcd/2` computes the greatest common divisor, and the GCD of 12 and 8 is 4.
Question 3: Which function in the Picat `string` module converts a string to uppercase?
- string_upper/1
- to_upper/1 (Correct answer)
- upcase_atom/1
- upper/1
Correct answer: to_upper/1
`to_upper/1` from the `string` module returns the uppercase version of a string.
Question 4: How do you import the `io` module in a Picat program?
- :- use_module(io).
- import io.
- :- import io. (Correct answer)
- module(io).
Correct answer: :- import io.
Picat uses the `:- import module_name.` directive to import a module.
Question 5: What does `maps:get(Map, Key, Default)` do when the key is not found in the map?
- Throws an exception
- Returns Default (Correct answer)
- Returns an empty map
- Fails silently
Correct answer: Returns Default
The three-argument form of `maps:get/3` returns the Default value when the Key is absent from Map.
Question 6: Which Picat `lists` module predicate checks if an element is a member of a list?
- contains/2
- member/2 (Correct answer)
- elem/2
- in/2
Correct answer: member/2
`member/2` is the standard predicate to test whether an element belongs to a list.
Question 7: In the Picat `util` module, what does `max_list/1` return?
- The sum of all elements
- The length of the list
- The maximum element in the list (Correct answer)
- The last element of the list
Correct answer: The maximum element in the list
`max_list/1` traverses the list and returns the largest numerical element.
Which Picat module provides the `sort/1` and `msort/1` predicates for list sorting?