Picat Picat String and I/O Operations 1 — Questions and Answers
Question 1: Which operator concatenates two strings or lists in Picat?
- concat(S1, S2)
- S1 ++ S2 (Correct answer)
- append(S1, S2)
- join(S1, S2)
Correct answer: S1 ++ S2
In Picat, the `++` operator concatenates two strings or lists.
Question 2: How are strings internally represented in Picat?
- As arrays of characters
- As atoms
- As lists of character codes (Correct answer)
- As byte arrays
Correct answer: As lists of character codes
Strings in Picat are represented as lists of character codes (integers), similar to traditional Prolog.
Question 3: Which built-in converts a number to its string representation in Picat?
- int_to_str(N)
- to_string(N) (Correct answer)
- number_to_atom(N)
- char_code(N)
Correct answer: to_string(N)
`to_string(N)` converts a number (or any term) to its string representation in Picat.
Question 4: What does `split(Str, Sep)` return in Picat?
- A boolean indicating whether Sep exists
- A list of substrings split by Sep (Correct answer)
- The index of the first Sep occurrence
- A count of Sep occurrences
Correct answer: A list of substrings split by Sep
`split(Str, Sep)` returns a list of substrings produced by splitting Str on the separator Sep.
Question 5: Which predicate reads a full line from standard input in Picat?
- read_line(L) (Correct answer)
- get_line(L)
- readline(L)
- input_line(L)
Correct answer: read_line(L)
`read_line(L)` reads one line from standard input and unifies it with L.
Question 6: How do you obtain the length of a string in Picat?
- string_length(S)
- len(S)
- length(S) (Correct answer)
- size(S)
Correct answer: length(S)
`length(S)` returns the number of elements in a list or characters in a string since strings are lists.
Which operator concatenates two strings or lists in Picat?