4 ms·
Where are you getting your idea of what belongs in a production environment, in the context of Lisp? The accessor functions like caddr should probably be avoid
by kazinator 4y ago
Where are you getting your idea of what belongs in a production environment, in the context of Lisp?
The accessor functions like caddr should probably be avoided in code which is using cons cells as linear lists. If someone is writing a server that pops requests from a list, and I see caddr in that code, I will probably flag that in the review.
The functions are useful in code that manipulates nested cons cell structure, and it's important to be familiar with them.
I'd prefer destructuring or pattern matching to be used.
Some Lisp dialects don't have a pattern matching library included; it requires third party code. Destructuring can be cumbersome because it has a variable in every position of the pattern.
Say we have a variable called obj which holds something like (1 ((2 3)) ...) and we are interested in extracting the 3, and don't care about the other values. Destructuring can be cumbersome; e.g.
(destructuring-bind (a ((b c)) &rest r) obj
c) ;; a, b and r are ignored
Here, there may be excellent justification in just doing (cadaadr obj), if you happen to have the function to that depth. You likely don't, so a break-up into two is required such as (cadar (cadr obj)) and that may even be more readable, since "cadar" and "caddr" are recognizable idioms.
In some lower level parts of a Lisp implementation, you may not have any pattern matching or destructuring available, due to the bootstrapping chicken-and-egg problem: the code is helping to implement that.
The meta-circular interpreter is like that. It could use destructuring, but then the goal is for the meta-circular interpreter to be able to handle all the constructs that are used in its own code; thus a definition of destructuring would be required, making it a lot larger.