3 ms·
Toward the end of `print_obj()`, we see: if (is_pair(cdr(ob))) { printf(" "); print_obj(cdr(ob), 0); } How could this `if`
by raldi 9y ago
Toward the end of `print_obj()`, we see:
if (is_pair(cdr(ob))) {
printf(" ");
print_obj(cdr(ob), 0);
}
How could this `if` statement ever evaluate to false? We already verified that `cdr(ob) != 0`, and the CDR can never be a plain old string, so isn't this `if` superfluous?
- orodley 9y agoI don't know about this implementation in particular, but in general a cons cell is just an object with two slots in it. You can use it to represent a list (by putting another cons or nil in the cdr), but you can also use it to represent other things. For example, a pair, by putting an arbitrary object in the car and cdr. This is a pretty common technique, see "a-list" for one application.
- rurban 9y agoNope. It still can be an atom. Only if it's a pair (i.e. a cons with two cells, not just one) it prints the next.