4 ms·
I know almost nothing about lisp, but what comes to mind is car, cdr which aren't exactly the most descriptive keywords of programming languages I have seen. (
by reitanqild 11y ago
I know almost nothing about lisp, but what comes to mind is car, cdr which aren't exactly the most descriptive keywords of programming languages I have seen.
(I think they are replaced in modern versions but my point still stands as I remember the old ones, not the new)
- kruhft 11y agoYes, sometimes 'car' and 'cdr' are replaced with 'first' and 'rest' and are some of the first things you cover when learning the language, so I don't think the names would really be hindering adoption for those that try to learn the language. The benefits of car and cdr are that they can be composed: (caadr l) instead of (car (car (cdr l))) for example.
- AnimalMuppet 11y agoWell, if you use "first" and "rest", then (caadr l) could become (firrest l) or something like that...
- bhrgunatha 11y agoI like Racket's second, third, fourth,... etc. [1] I don't think there's an equivalent to cddadr for example, but at that level of deconstruction you're better off abstracting the data structure (maybe a struct [2]) or using some other mechanism like match [3] [1] http://docs.racket-lang.org/reference/pairs.html?q=second#%28def._%28%28lib._racket%2Flist..rkt%29._second%29%29 http://docs.racket-lang.org/reference/pairs.html?q=second#%2... [2] http://docs.racket-lang.org/reference/define-struct.html?q=struct#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._struct%29%29 http://docs.racket-lang.org/reference/define-struct.html?q=s... [3] http://docs.racket-lang.org/reference/match.html?q=match#%28form._%28%28lib._racket%2Fmatch..rkt%29._match%29%29 http://docs.racket-lang.org/reference/match.html?q=match#%28...
- defgeneric 11y agoYes but can you do caaaaaar or caaddaar or cdaar, etc. with head and tail? In 5 characters with cadar you can express walking along a tree structure to get exactly the node you want.
- davexunit 11y agocar, cdr, cadr, and friends are discouraged in some Lisp communities where pattern matchers are available.
- AnimalMuppet 11y agoSure. caaaaaar -> heaaaaaad. cadar -> heaiad. It's one more character, but if you really want to express yourself that way, there's no reason you couldn't...