I'm still struggling with my own legacy code problem. I'm reviving an old LISP program from the early 1980s. Parts of it were written for the original Stanford AI Lab SAIL system in the 1970s. It last ran under Franz LISP in 1986.<p>My current struggle is with one line of code:<p><pre><code> (defun getenode (l) (cadr l))
</code></pre>
That ought to be simple enough. But it's being applied not to a list, but a "hunk". A "hunk" is an obsolete MacLISP concept.[1]. It's a block of memory which has N contiguous LISP cells, each with two pointers. This is the memory object underlying structures and arrays in MacLISP. Macros were used to create the illusion of structure data objects, with hunks underneath. However, you could still access a "hunk" with car, cdr, cxr, etc.<p>I'm converting this to Common LISP, which has real structures, but not hunks. That, with some new macro support, works for the regular structure operations. So far, so good.<p>But which element of the structure does (cadr l), which usually means the same thing as "(car (cdr l))", access? (cadr (list 0 1 2 4)) returns 1, so you'd think it would be field 1 of the structure. But no. It's more complicated and depends on how hunks are laid out in memory.<p>The Franz LISP manual from 1983 [2] says <i>"Although hunks are not list cells, you can still access the first two hunk elements with cdr and car and you can access any hunk element with cxr†."</i> At footnote "†", <i>"In a hunk, the function cdr references the first element and car the second."</i> This is backwards from the way lists behave.<p>A blog posting from 2008 about MacLISP says <i>"A Maclisp hunk was a structure like a cons cell that could hold an arbitrary number of pointers, up to total of 512. Each of these slots in a hunk was referred to as a numbered cxr, with a numbering scheme that went like this: ( cxr-1 cxr-2 cxr-3 ... cxr-n cxr-0 ). No matter how many slots were in the hunk, car was equivalent to (cxr 1 hunk) and cdr was equivalent to (cxr 0 hunk)."</i> Note that element 0 is at the end, which is even stranger. The documentation is silent about what "cadr" would do. Does it get element 2, or get element 0 and then apply "car" to it?<p>The original code [3] contains no relevant comments. I'm trying to figure out from the context what the original author, Greg Nelson, had in mind. He died in 2015.[4]<p>[1] <a href="http://www.mschaef.com/blog/tech/lisp/car-cdr.html" rel="nofollow">http://www.mschaef.com/blog/tech/lisp/car-cdr.html</a>
[2] <a href="http://www.softwarepreservation.org/projects/LISP/franz/Franz_Lisp_July_1983.pdf" rel="nofollow">http://www.softwarepreservation.org/projects/LISP/franz/Fran...</a>
[3] <a href="https://github.com/John-Nagle/pasv/blob/master/src/CPC4/z.lisp" rel="nofollow">https://github.com/John-Nagle/pasv/blob/master/src/CPC4/z.li...</a>
[4] <a href="https://en.wikipedia.org/wiki/Greg_Nelson_(computer_scientist)" rel="nofollow">https://en.wikipedia.org/wiki/Greg_Nelson_(computer_scientis...</a>