Picat Data Structures and Types 3 — Questions and Answers
Question 1: In Picat, what type does the literal `"hello"` (double-quoted) have?
- List of character codes
- Array of characters
- String — its own distinct type (Correct answer)
- Atom
Correct answer: String — its own distinct type
In Picat, double-quoted literals are of the `string` type, which is distinct from atoms and lists.
Question 2: Which predicate tests if X is a Picat string (double-quoted value)?
- string(X) (Correct answer)
- atom(X)
- is_str(X)
- chars(X)
Correct answer: string(X)
`string(X)` succeeds when X is a Picat string literal (double-quoted), distinguishing it from atoms.
Question 3: How do you convert integer N to its atom representation in Picat?
- int_to_atom(N)
- atom_number(A, N)
- number_codes(N, Cs)
- to_atom(N) (Correct answer)
Correct answer: to_atom(N)
`to_atom(N)` converts any Picat term including integers to its atom representation.
Question 4: What does `string_codes("ab", Cs)` bind Cs to in Picat?
- [97, 98] (Correct answer)
- [a, b]
- "ab"
- Error: use string_chars instead
Correct answer: [97, 98]
`string_codes/2` converts a string to a list of Unicode code points; 97 = 'a' and 98 = 'b'.
Question 5: What does `atom_length(hello, N)` bind N to in Picat?
- 4
- 5 (Correct answer)
- 6
- Error: use string_length for atoms
Correct answer: 5
`atom_length/2` counts the characters in the atom's name; 'hello' has 5 characters.
Question 6: Which predicate checks if X is an atom (not a string or number) in Picat?
- is_atom(X)
- symbol(X)
- atom(X) (Correct answer)
- term(X)
Correct answer: atom(X)
`atom(X)` is the standard Picat predicate that succeeds when X is an unquoted atom like `hello` or `foo`.
Question 7: How do you convert the string "42" to the integer 42 in Picat?
- to_integer("42") (Correct answer)
- integer("42")
- string_to_int("42")
- parse_int("42")
Correct answer: to_integer("42")
`to_integer/1` is Picat's built-in for converting strings and other terms to integer values.
In Picat, what type does the literal `"hello"` (double-quoted) have?