7. What happens when a clause inside with does not match?
- with stops and returns the non-matching value, or passes it to the else block
- The program crashes always
- The clause is skipped and the next one runs
- It retries the clause
Show answer
Answer: with stops and returns the non-matching value, or passes it to the else block
with short-circuits on the first non-matching value.
Lesson: case, cond, if and with
8. What is the difference between a protocol and a behaviour?
- They are identical
- Behaviours dispatch on data types
- Protocols only work with strings
- Protocols dispatch on the data type of a value; behaviours define functions a module must implement
Show answer
Answer: Protocols dispatch on the data type of a value; behaviours define functions a module must implement
Protocols give data-type polymorphism; behaviours are module contracts.
Lesson: Structs, Protocols and Behaviours