You should be automatically redirected . If not, visit
http://newlisper.wordpress.com
and update your bookmarks.

27/06/2008

Vacuum-tube Lisp

I love the idea of a vacuum-tube computer running Lisp. Here's Steve Russell:

I wrote the first implementation of a LISP interpreter on the IBM 704 at MIT in early in 1959.

The 704 family (704, 709, 7090) had "Address" and "Decrement" fields that were 15 bits long in some of the looping instructions. There were also special load and store instructions that moved these 15-bit addresses between memory and the index regiseters ( 3 on the 704, 7 on the others )

We had devised a representation for list structure that took advantage of these instructions.

Because of an unfortunate temporary lapse of inspiration, we couldn't think of any other names for the 2 pointers in a list node than "address" and "decrement", so we called the functions CAR for "Contents of Address of Register" and CDR for "Contents of Decrement of Register".

After several months and giving a few classes in LISP, we realized that "first" and "rest" were better names, and we (John McCarthy, I and some of the rest of the AI Project) tried to get people to use them instead.

Alas, it was too late! We couldn't make it stick at all. So we have CAR and CDR.

Like Steve, I much prefer first and rest to car and cdr. This approach is evident throughout newLISP, which usually leans towards a user-friendly and abbreviation-free approach to function naming.

But, although car and cdr have been uninspired for nearly 50 years, they have survived because they offer an extra geeky ability: you can add more a and d letters between the "c" and "r", to produce functions with even weirder names. So caddr finds the car of the cdr of the cdr; you read from left to right, although the functions are applied from right to left as usual.

To be honest, I don't know how I've managed to write any code at all in newLISP without having this readable and user-friendly syntax at my fingertips. So it's time for newLISP to be 'cdadderized':

(define (car x) (first x))
(define (cdr x) (rest x))

(define (cdadderize x) 
  (inc 'x)
  (set 'results '())
  (until (= x 0)
     (push   (% x 2) results)
     (set 'x (/ x 2)))
  (set 'results (rest results) 'f-name results)
  (map (fn (a b) (replace a results b)) '(0 1) '("(car " "(cdr "))
  (push (string "x"  (dup ")" (length results))) results -1)
  (set 'results (join results))
  (map (fn (a b) (replace a f-name b)) '(0 1) '("a" "d"))
  (letex ((fnm   (sym (string "c" (join f-name) "r")))
          (body results))
    (define (fnm x) (eval-string body))
    fnm))

(for (i 3 1022) (cdadderize i)) ; we did 1 and 2 :)

Not the prettiest code, but let's run it and look at the new functions that have been defined:

(filter (fn (s) 
    (and (starts-with  (name s) "ca|cd" 0) 
         (ends-with (name s) "r"))) 
    (symbols))
;->
(caaaaaaaaaar caaaaaaaaadr caaaaaaaaar caaaaaaaadr caaaaaaaar caaaaaaadar caaaaaaaddr 
caaaaaaadr caaaaaaar caaaaaadaar caaaaaadadr caaaaaadar caaaaaaddar caaaaaadddr 
caaaaaaddr caaaaaadr caaaaaar caaaaadaaar caaaaadaadr caaaaadaar caaaaadadar caaaaadaddr 
caaaaadadr caaaaadar caaaaaddaar caaaaaddadr caaaaaddar caaaaadddar caaaaaddddr 
caaaaadddr caaaaaddr caaaaadr caaaaar caaaadaaaar caaaadaaadr caaaadaaar caaaadaadar 
caaaadaaddr caaaadaadr caaaadaar caaaadadaar caaaadadadr caaaadadar caaaadaddar 
caaaadadddr caaaadaddr caaaadadr caaaadar caaaaddaaar caaaaddaadr caaaaddaar caaaaddadar 
caaaaddaddr caaaaddadr caaaaddar caaaadddaar caaaadddadr caaaadddar caaaaddddar 
caaaadddddr caaaaddddr caaaadddr caaaaddr caaaadr caaaar caaadaaaaar caaadaaaadr 
caaadaaaar caaadaaadar caaadaaaddr caaadaaadr caaadaaar caaadaadaar caaadaadadr 
caaadaadar caaadaaddar caaadaadddr caaadaaddr caaadaadr caaadaar caaadadaaar caaadadaadr 
caaadadaar caaadadadar caaadadaddr caaadadadr caaadadar caaadaddaar caaadaddadr 
caaadaddar caaadadddar caaadaddddr caaadadddr caaadaddr caaadadr caaadar caaaddaaaar 
caaaddaaadr caaaddaaar caaaddaadar caaaddaaddr caaaddaadr caaaddaar caaaddadaar 
caaaddadadr caaaddadar caaaddaddar caaaddadddr caaaddaddr caaaddadr caaaddar caaadddaaar 
caaadddaadr caaadddaar caaadddadar caaadddaddr caaadddadr caaadddar caaaddddaar 
caaaddddadr caaaddddar caaadddddar caaaddddddr caaadddddr caaaddddr caaadddr caaaddr 
caaadr caaar caadaaaaaar caadaaaaadr caadaaaaar caadaaaadar caadaaaaddr caadaaaadr 
caadaaaar caadaaadaar caadaaadadr caadaaadar caadaaaddar caadaaadddr caadaaaddr 
caadaaadr caadaaar caadaadaaar caadaadaadr caadaadaar caadaadadar caadaadaddr caadaadadr 
caadaadar caadaaddaar caadaaddadr caadaaddar caadaadddar caadaaddddr caadaadddr 
caadaaddr caadaadr caadaar caadadaaaar caadadaaadr caadadaaar caadadaadar caadadaaddr 
caadadaadr caadadaar caadadadaar caadadadadr caadadadar caadadaddar caadadadddr 
caadadaddr caadadadr caadadar caadaddaaar caadaddaadr caadaddaar caadaddadar caadaddaddr 
caadaddadr caadaddar caadadddaar caadadddadr caadadddar caadaddddar caadadddddr 
caadaddddr caadadddr caadaddr caadadr caadar caaddaaaaar caaddaaaadr caaddaaaar 
caaddaaadar caaddaaaddr caaddaaadr caaddaaar caaddaadaar caaddaadadr caaddaadar 
caaddaaddar caaddaadddr caaddaaddr caaddaadr caaddaar caaddadaaar caaddadaadr caaddadaar 
caaddadadar caaddadaddr caaddadadr caaddadar caaddaddaar caaddaddadr caaddaddar 
caaddadddar caaddaddddr caaddadddr caaddaddr caaddadr caaddar caadddaaaar caadddaaadr 
caadddaaar caadddaadar caadddaaddr caadddaadr caadddaar caadddadaar caadddadadr 
caadddadar caadddaddar caadddadddr caadddaddr caadddadr caadddar caaddddaaar caaddddaadr 
caaddddaar caaddddadar caaddddaddr caaddddadr caaddddar caadddddaar caadddddadr 
caadddddar caaddddddar caadddddddr caaddddddr caadddddr caaddddr caadddr caaddr 
caadr caar cadaaaaaaar cadaaaaaadr cadaaaaaar cadaaaaadar cadaaaaaddr cadaaaaadr 
cadaaaaar cadaaaadaar cadaaaadadr cadaaaadar cadaaaaddar cadaaaadddr cadaaaaddr 
cadaaaadr cadaaaar cadaaadaaar cadaaadaadr cadaaadaar cadaaadadar cadaaadaddr cadaaadadr 
cadaaadar cadaaaddaar cadaaaddadr cadaaaddar cadaaadddar cadaaaddddr cadaaadddr 
cadaaaddr cadaaadr cadaaar cadaadaaaar cadaadaaadr cadaadaaar cadaadaadar cadaadaaddr 
cadaadaadr cadaadaar cadaadadaar cadaadadadr cadaadadar cadaadaddar cadaadadddr 
cadaadaddr cadaadadr cadaadar cadaaddaaar cadaaddaadr cadaaddaar cadaaddadar cadaaddaddr 
cadaaddadr cadaaddar cadaadddaar cadaadddadr cadaadddar cadaaddddar cadaadddddr 
cadaaddddr cadaadddr cadaaddr cadaadr cadaar cadadaaaaar cadadaaaadr cadadaaaar 
cadadaaadar cadadaaaddr cadadaaadr cadadaaar cadadaadaar cadadaadadr cadadaadar 
cadadaaddar cadadaadddr cadadaaddr cadadaadr cadadaar cadadadaaar cadadadaadr cadadadaar 
cadadadadar cadadadaddr cadadadadr cadadadar cadadaddaar cadadaddadr cadadaddar 
cadadadddar cadadaddddr cadadadddr cadadaddr cadadadr cadadar cadaddaaaar cadaddaaadr 
cadaddaaar cadaddaadar cadaddaaddr cadaddaadr cadaddaar cadaddadaar cadaddadadr 
cadaddadar cadaddaddar cadaddadddr cadaddaddr cadaddadr cadaddar cadadddaaar cadadddaadr 
cadadddaar cadadddadar cadadddaddr cadadddadr cadadddar cadaddddaar cadaddddadr 
cadaddddar cadadddddar cadaddddddr cadadddddr cadaddddr cadadddr cadaddr cadadr 
cadar caddaaaaaar caddaaaaadr caddaaaaar caddaaaadar caddaaaaddr caddaaaadr caddaaaar 
caddaaadaar caddaaadadr caddaaadar caddaaaddar caddaaadddr caddaaaddr caddaaadr 
caddaaar caddaadaaar caddaadaadr caddaadaar caddaadadar caddaadaddr caddaadadr caddaadar 
caddaaddaar caddaaddadr caddaaddar caddaadddar caddaaddddr caddaadddr caddaaddr 
caddaadr caddaar caddadaaaar caddadaaadr caddadaaar caddadaadar caddadaaddr caddadaadr 
caddadaar caddadadaar caddadadadr caddadadar caddadaddar caddadadddr caddadaddr 
caddadadr caddadar caddaddaaar caddaddaadr caddaddaar caddaddadar caddaddaddr caddaddadr 
caddaddar caddadddaar caddadddadr caddadddar caddaddddar caddadddddr caddaddddr 
caddadddr caddaddr caddadr caddar cadddaaaaar cadddaaaadr cadddaaaar cadddaaadar 
cadddaaaddr cadddaaadr cadddaaar cadddaadaar cadddaadadr cadddaadar cadddaaddar 
cadddaadddr cadddaaddr cadddaadr cadddaar cadddadaaar cadddadaadr cadddadaar cadddadadar 
cadddadaddr cadddadadr cadddadar cadddaddaar cadddaddadr cadddaddar cadddadddar 
cadddaddddr cadddadddr cadddaddr cadddadr cadddar caddddaaaar caddddaaadr caddddaaar 
caddddaadar caddddaaddr caddddaadr caddddaar caddddadaar caddddadadr caddddadar 
caddddaddar caddddadddr caddddaddr caddddadr caddddar cadddddaaar cadddddaadr cadddddaar 
cadddddadar cadddddaddr cadddddadr cadddddar caddddddaar caddddddadr caddddddar 
cadddddddar cadddddddddr caddddddddr cadddddddr caddddddr cadddddr caddddr cadddr 
caddr cadr car cdaaaaaaaar cdaaaaaaadr cdaaaaaaar cdaaaaaadar cdaaaaaaddr cdaaaaaadr 
cdaaaaaar cdaaaaadaar cdaaaaadadr cdaaaaadar cdaaaaaddar cdaaaaadddr cdaaaaaddr 
cdaaaaadr cdaaaaar cdaaaadaaar cdaaaadaadr cdaaaadaar cdaaaadadar cdaaaadaddr cdaaaadadr 
cdaaaadar cdaaaaddaar cdaaaaddadr cdaaaaddar cdaaaadddar cdaaaaddddr cdaaaadddr 
cdaaaaddr cdaaaadr cdaaaar cdaaadaaaar cdaaadaaadr cdaaadaaar cdaaadaadar cdaaadaaddr 
cdaaadaadr cdaaadaar cdaaadadaar cdaaadadadr cdaaadadar cdaaadaddar cdaaadadddr 
cdaaadaddr cdaaadadr cdaaadar cdaaaddaaar cdaaaddaadr cdaaaddaar cdaaaddadar cdaaaddaddr 
cdaaaddadr cdaaaddar cdaaadddaar cdaaadddadr cdaaadddar cdaaaddddar cdaaadddddr 
cdaaaddddr cdaaadddr cdaaaddr cdaaadr cdaaar cdaadaaaaar cdaadaaaadr cdaadaaaar 
cdaadaaadar cdaadaaaddr cdaadaaadr cdaadaaar cdaadaadaar cdaadaadadr cdaadaadar 
cdaadaaddar cdaadaadddr cdaadaaddr cdaadaadr cdaadaar cdaadadaaar cdaadadaadr cdaadadaar 
cdaadadadar cdaadadaddr cdaadadadr cdaadadar cdaadaddaar cdaadaddadr cdaadaddar 
cdaadadddar cdaadaddddr cdaadadddr cdaadaddr cdaadadr cdaadar cdaaddaaaar cdaaddaaadr 
cdaaddaaar cdaaddaadar cdaaddaaddr cdaaddaadr cdaaddaar cdaaddadaar cdaaddadadr 
cdaaddadar cdaaddaddar cdaaddadddr cdaaddaddr cdaaddadr cdaaddar cdaadddaaar cdaadddaadr 
cdaadddaar cdaadddadar cdaadddaddr cdaadddadr cdaadddar cdaaddddaar cdaaddddadr 
cdaaddddar cdaadddddar cdaaddddddr cdaadddddr cdaaddddr cdaadddr cdaaddr cdaadr 
cdaar cdadaaaaaar cdadaaaaadr cdadaaaaar cdadaaaadar cdadaaaaddr cdadaaaadr cdadaaaar 
cdadaaadaar cdadaaadadr cdadaaadar cdadaaaddar cdadaaadddr cdadaaaddr cdadaaadr 
cdadaaar cdadaadaaar cdadaadaadr cdadaadaar cdadaadadar cdadaadaddr cdadaadadr cdadaadar 
cdadaaddaar cdadaaddadr cdadaaddar cdadaadddar cdadaaddddr cdadaadddr cdadaaddr 
cdadaadr cdadaar cdadadaaaar cdadadaaadr cdadadaaar cdadadaadar cdadadaaddr cdadadaadr 
cdadadaar cdadadadaar cdadadadadr cdadadadar cdadadaddar cdadadadddr cdadadaddr 
cdadadadr cdadadar cdadaddaaar cdadaddaadr cdadaddaar cdadaddadar cdadaddaddr cdadaddadr 
cdadaddar cdadadddaar cdadadddadr cdadadddar cdadaddddar cdadadddddr cdadaddddr 
cdadadddr cdadaddr cdadadr cdadar cdaddaaaaar cdaddaaaadr cdaddaaaar cdaddaaadar 
cdaddaaaddr cdaddaaadr cdaddaaar cdaddaadaar cdaddaadadr cdaddaadar cdaddaaddar 
cdaddaadddr cdaddaaddr cdaddaadr cdaddaar cdaddadaaar cdaddadaadr cdaddadaar cdaddadadar 
cdaddadaddr cdaddadadr cdaddadar cdaddaddaar cdaddaddadr cdaddaddar cdaddadddar 
cdaddaddddr cdaddadddr cdaddaddr cdaddadr cdaddar cdadddaaaar cdadddaaadr cdadddaaar 
cdadddaadar cdadddaaddr cdadddaadr cdadddaar cdadddadaar cdadddadadr cdadddadar 
cdadddaddar cdadddadddr cdadddaddr cdadddadr cdadddar cdaddddaaar cdaddddaadr cdaddddaar 
cdaddddadar cdaddddaddr cdaddddadr cdaddddar cdadddddaar cdadddddadr cdadddddar 
cdaddddddar cdadddddddr cdaddddddr cdadddddr cdaddddr cdadddr cdaddr cdaderizer 
cdadr cdar cddaaaaaaar cddaaaaaadr cddaaaaaar cddaaaaadar cddaaaaaddr cddaaaaadr 
cddaaaaar cddaaaadaar cddaaaadadr cddaaaadar cddaaaaddar cddaaaadddr cddaaaaddr 
cddaaaadr cddaaaar cddaaadaaar cddaaadaadr cddaaadaar cddaaadadar cddaaadaddr cddaaadadr 
cddaaadar cddaaaddaar cddaaaddadr cddaaaddar cddaaadddar cddaaaddddr cddaaadddr 
cddaaaddr cddaaadr cddaaar cddaadaaaar cddaadaaadr cddaadaaar cddaadaadar cddaadaaddr 
cddaadaadr cddaadaar cddaadadaar cddaadadadr cddaadadar cddaadaddar cddaadadddr 
cddaadaddr cddaadadr cddaadar cddaaddaaar cddaaddaadr cddaaddaar cddaaddadar cddaaddaddr 
cddaaddadr cddaaddar cddaadddaar cddaadddadr cddaadddar cddaaddddar cddaadddddr 
cddaaddddr cddaadddr cddaaddr cddaadr cddaar cddadaaaaar cddadaaaadr cddadaaaar 
cddadaaadar cddadaaaddr cddadaaadr cddadaaar cddadaadaar cddadaadadr cddadaadar 
cddadaaddar cddadaadddr cddadaaddr cddadaadr cddadaar cddadadaaar cddadadaadr cddadadaar 
cddadadadar cddadadaddr cddadadadr cddadadar cddadaddaar cddadaddadr cddadaddar 
cddadadddar cddadaddddr cddadadddr cddadaddr cddadadr cddadar cddaddaaaar cddaddaaadr 
cddaddaaar cddaddaadar cddaddaaddr cddaddaadr cddaddaar cddaddadaar cddaddadadr 
cddaddadar cddaddaddar cddaddadddr cddaddaddr cddaddadr cddaddar cddadddaaar cddadddaadr 
cddadddaar cddadddadar cddadddaddr cddadddadr cddadddar cddaddddaar cddaddddadr 
cddaddddar cddadddddar cddaddddddr cddadddddr cddaddddr cddadddr cddaddr cddadr 
cddar cdddaaaaaar cdddaaaaadr cdddaaaaar cdddaaaadar cdddaaaaddr cdddaaaadr cdddaaaar 
cdddaaadaar cdddaaadadr cdddaaadar cdddaaaddar cdddaaadddr cdddaaaddr cdddaaadr 
cdddaaar cdddaadaaar cdddaadaadr cdddaadaar cdddaadadar cdddaadaddr cdddaadadr cdddaadar 
cdddaaddaar cdddaaddadr cdddaaddar cdddaadddar cdddaaddddr cdddaadddr cdddaaddr 
cdddaadr cdddaar cdddadaaaar cdddadaaadr cdddadaaar cdddadaadar cdddadaaddr cdddadaadr 
cdddadaar cdddadadaar cdddadadadr cdddadadar cdddadaddar cdddadadddr cdddadaddr 
cdddadadr cdddadar cdddaddaaar cdddaddaadr cdddaddaar cdddaddadar cdddaddaddr cdddaddadr 
cdddaddar cdddadddaar cdddadddadr cdddadddar cdddaddddar cdddadddddr cdddaddddr 
cdddadddr cdddaddr cdddadr cdddar cddddaaaaar cddddaaaadr cddddaaaar cddddaaadar 
cddddaaaddr cddddaaadr cddddaaar cddddaadaar cddddaadadr cddddaadar cddddaaddar 
cddddaadddr cddddaaddr cddddaadr cddddaar cddddadaaar cddddadaadr cddddadaar cddddadadar 
cddddadaddr cddddadadr cddddadar cddddaddaar cddddaddadr cddddaddar cddddadddar 
cddddaddddr cddddadddr cddddaddr cddddadr cddddar cdddddaaaar cdddddaaadr cdddddaaar 
cdddddaadar cdddddaaddr cdddddaadr cdddddaar cdddddadaar cdddddadadr cdddddadar 
cdddddaddar cdddddadddr cdddddaddr cdddddadr cdddddar cddddddaaar cddddddaadr cddddddaar 
cddddddadar cddddddaddr cddddddadr cddddddar cdddddddaar cdddddddadr cdddddddar 
cddddddddar cdddddddddr cddddddddr cdddddddr cddddddr cdddddr cddddr cdddr cddr 
cdr)

Some useful tools there - surely some of these functions would be proud to appear in any Common Lisp program? How about the stretch-limo caaaaaaaaar, for one ("My god, it's full of cars")? Then there's cadadar - north of the USA, if you have a cold. A few are useful in other ways, too: cdddddddddr provides excellent tonguing practice for woodwind players, especially the bassoonists among you.

By the way, for compatibility with Common Lisp, it's not necessary to go all the way up 1022. Call (cdadderize 14) to give you:

(caaar caadr caar cadar caddr cadr car cdaar cdadr cdar cddar cdddr cddr cdr)

whereas 30 gives you everything up to cddddr.

To be honest, I can't see myself using these very much. Well, OK: I will never use these. But I like the idea that the ever-adaptable Lisp was once written for vacuum-tubes and can still run like the wind on my iMac.

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home