[ prog / sol / mona ]

prog


cddr

18 2024-08-18 20:41

midwit discussion where situational is treated as universal

common lisp has like dozen different ways to destructure a list from which you can choose based on what you're doing. often those ways trade greater upfront work, for lesser domain work. but sometimes you start with more domain work, and then having identified an abstraction you factor it out.

cons exist at the lowest level of abstraction, it's a fundamental mechanism for dealing with the fact that von neumann machine doesn't let you resize things without relocating. you can build more complicated structures out of cons, like lists, but also variations on structs, or more elaborate algorithm specific data structures.

the lowest level way of manipulating a cons-cells-based-thing is using a combination of cars and cdrs, where c[ad]r is a clever hack that lets you reach down the cons indirection tree in a single call. after a while one might lose track of all the necessary c[ad]r combinations, so in the olden days you'd wrap an elaborate c[ad]r in its own semantic function. these days you have more mechanisms, like wrapping your lists in defstrcturs, or replacing lists with structs altogether, or whatever.

there is, to conclude, no one way. you can write an elaborate chunky code that's got caddrs and cddars all over hte place, and refactoring it to some sanity later. or maybe you never refactor it because it's good enough. but it's handy that mechanism is there.

30


VIP:

do not edit these