What Happens When You Mix Java with a 1960 IBM Mainframe
I&#x27;m still struggling with my own legacy code problem. I&#x27;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&#x27;s being applied not to a list, but a &quot;hunk&quot;. A &quot;hunk&quot; is an obsolete MacLISP concept.[1]. It&#x27;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 &quot;hunk&quot; with car, cdr, cxr, etc.<p>I&#x27;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 &quot;(car (cdr l))&quot;, access?  (cadr (list 0 1 2 4)) returns 1, so you&#x27;d think it would be field 1 of the structure. But no. It&#x27;s more complicated and depends on how hunks are laid out in memory.<p>The Franz LISP manual from 1983 [2] says <i>&quot;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†.&quot;</i> At footnote &quot;†&quot;, <i>&quot;In a hunk, the function cdr references the first element and car the second.&quot;</i>  This is backwards from the way lists behave.<p>A blog posting from 2008 about MacLISP says <i>&quot;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).&quot;</i> Note that element 0 is at the end, which is even stranger.  The documentation is silent about what &quot;cadr&quot; would do. Does it get element 2, or get element 0 and then apply &quot;car&quot; to it?<p>The original code [3] contains no relevant comments.  I&#x27;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:&#x2F;&#x2F;www.mschaef.com&#x2F;blog&#x2F;tech&#x2F;lisp&#x2F;car-cdr.html" rel="nofollow">http:&#x2F;&#x2F;www.mschaef.com&#x2F;blog&#x2F;tech&#x2F;lisp&#x2F;car-cdr.html</a>
[2] <a href="http:&#x2F;&#x2F;www.softwarepreservation.org&#x2F;projects&#x2F;LISP&#x2F;franz&#x2F;Franz_Lisp_July_1983.pdf" rel="nofollow">http:&#x2F;&#x2F;www.softwarepreservation.org&#x2F;projects&#x2F;LISP&#x2F;franz&#x2F;Fran...</a>
[3] <a href="https:&#x2F;&#x2F;github.com&#x2F;John-Nagle&#x2F;pasv&#x2F;blob&#x2F;master&#x2F;src&#x2F;CPC4&#x2F;z.lisp" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;John-Nagle&#x2F;pasv&#x2F;blob&#x2F;master&#x2F;src&#x2F;CPC4&#x2F;z.li...</a>
[4] <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Greg_Nelson_(computer_scientist)" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Greg_Nelson_(computer_scientis...</a>