Lua is by far the best scripting language I’ve ever had the pleasure of using. It’s joy to embed, it’s fun to use, and here’s the kicker: It’s more like Lisp/Scheme than you think. I recently saw an absolutely crazy implementation of linked lists, far crazier than the standard Lua implementation. Basically, implementing cons, car, and cdr gets us the linked list for free. The table based implementation may be faster. Note that this idea comes right out of the MIT Scheme lectures, and I believe it’s also in SICP.

```function cons(a,b)
return function (p)
if p == 1 then
return a
end
if p == 2 then
return b
end
end
end
function car(l)
return l(1)
end
function cdr(l)
return l(2)
end
function cdar(l)
return car(cdr(l))
end
function cddr(l)
return cdr(cdr(l))
end
function cddar(l)
return car(cddr(l))
end
local x = cons(1,cons(2,cons(3,nil)))
print(car(x))
print(cdar(x))
print(cddar(x))
local y = x
while y do
print(car(y))
y = cdr(y)
end
```

Consider the same definitions in Scheme:

```(define (cons a b)
(lambda (p)
(if (= p 1) a b)))
(define (car x)
(x 1))
(define (cdr x)
(x 2))
(define (cdar x)
(car (cdr x)))
(define (cddr x)
(cdr (cdr x)))
(define (cddar x)
(car (cddr x)))
(define x (cons 1 (cons 2 (cons 3 '()))))
(car x)
(cdar x)
(cddar x)
(define (while x)
(cond
((empty? x) (display "Done"))
(else
(display (format "~a\n" (car x)))
(while (cdr x)))))
(while x)
```

In all fairness though, Lua would allow us to define even the loop the same, such as:

```function whilex(x)
if x then
print(car(x))
whilex(cdr(x))
else
print("Done")
end
end
whilex(x)
```