2 ms·
If you ever wondered why Lisp has CAR and CDR, this explains it.
by drob518 1y ago
If you ever wondered why Lisp has CAR and CDR, this explains it.
- kazinator 1y agoIt doesn't fully explain it, but drops some hints: "The other main advantage of the algebraic notation for list structure processing was first noticed by Gelernter." That's one of the authors of the Fortran-compiled List-processing Language (FLPL) in which thef unctions XCARF and XCDRF were introduced. MacCarthy drops a hint that he actually had something to do with Gelernter's work and his choices: "Algebraic notation for list processing is not used by Net'Jell, Simon and Shaw, pelhaps beaause to do so is most convenient when a compiler is available, but is used by Gelernter in the geometry program. This was accomplished (on the advice of the present author) by using the Fortran compiler together with a set of machine language coded functions for handling the primitive list processes that go from one element of a list to the next"
- coolThingsFirst 1y agoI think the main reason is car/cdr permits elegant recursive solutions to problems.
- bear8642 1y agomore the names then the functions themselves
- antonvs 1y agoFor those who may not be familiar: CAR = Contents of Address Register, corresponding to the head element of a list. CDR = Contents of Decrement Register, corresponding to a pointer to the "rest" of a list, i.e. to a machine word containing the next link in the list. This is hinted at in the paper by this: > "Each computer word of a list in addition to containing a datum also contains the address of the word containing the next element of the list. 0 for the address of the next element indicates the last element. If one element of an expression is a subexpression the word corresponding to this element contains the address of the word containing the first element of the subexpression. In the IBM 704 or 709 whose 36 bit word is divided (for the convenient use of certain machine instructions) into two 15 bit parts (address and decrement) and two 3 bit parts (prefix and tag) lists are represented by storing in the decrement part of a word the address (in our system actually the complement of the address) of the next word or the list." The choice of names is rather implementation-specific (and if memory serves, this may have been a choice by the person who coded the original LISP interpreter, not McCarthy himself.) But the mapping of the abstract concept of a linked list to a usable machine representation, built into the core of a programming language, was impressive. FORTRAN and COBOL had nothing like this.
- tug2024 1y ago[dead]