May 2018
Beginner to intermediate
290 pages
6h 43m
English
Possibly the easiest mistake you can make with a record is to attempt to get a value into a field and to miss. While this code may look plausible, it’s nonsense:
| | (map->FictionalCharacter {:full-name "Elizabeth Bennet" |
| | :book "Pride & Prejudice" |
| | :written-by "Austen"}) |
The trouble is that fields in FictionalCharacter are called name, appears-in, and author, not full-name, book, and written-by. The expression in the preceding code will give you a six-field record, with the three built-in fields set to nil, complemented by three additional fields—remember, records are also maps— set to the values we see in the code.
You can come to the same unfortunate end with botched uses of assoc:
| | (assoc elizabeth :book "Pride ... |
Read now
Unlock full access