Picat Data Structures and Types 5 — Questions and Answers
Question 1: What does `number(3.14)` return in Picat?
- false
- Error: 3.14 is a float not a number
- true (Correct answer)
- float
Correct answer: true
`number/1` succeeds for both integers and floats; 3.14 is a float and therefore a number.
Question 2: What does `integer(3.0)` evaluate to in Picat?
- true
- 3
- Error
- false (Correct answer)
Correct answer: false
`integer/1` checks the type precisely; 3.0 is a float even though its value is whole, so it returns false.
Question 3: What does `round(3.7)` return in Picat?
- 3
- 4 (Correct answer)
- 3.7
- Error: round is not a Picat built-in
Correct answer: 4
`round/1` rounds to the nearest integer; 3.7 rounds up to 4.
Question 4: What is the result of `X is 7 // 2` in Picat?
- 3.5
- 4
- 3 (Correct answer)
- Error: use div instead of //
Correct answer: 3
The `//` operator performs integer division truncating toward zero; 7 // 2 = 3.
Question 5: Which function converts a number to its string representation in Picat?
- number_to_string(N)
- str(N)
- num_string(N)
- to_string(N) (Correct answer)
Correct answer: to_string(N)
`to_string(N)` converts any Picat term, including numbers, to its string representation.
Question 6: What does `var(X)` return immediately before X is bound to any value?
- false
- true (Correct answer)
- Error — X must be bound first
- 'unbound'
Correct answer: true
`var/1` succeeds (returns true) when its argument is an unbound logic variable.
Question 7: In Picat, what does `nonvar(42)` return?
- false
- 42
- true (Correct answer)
- Error
Correct answer: true
`nonvar(X)` succeeds when X is not an unbound variable; the integer 42 is fully bound, so it returns true.
What does `number(3.14)` return in Picat?