Lisp: Become the STD


One of the great features many Lisp languages share is that they try to have an extremely tiny core language and then just implement everything else in it.

To the point that out of the relatively small standard library in Common Lisp which exports 978 symbols, only 25 of these are special forms that aren't implemented as functions or macros. And of these special forms some are meant for specific usecases, I'd be willing to say 18 of these are the ones appearing in all code.

97%3%Ratio of symbols in CLSymbolsSpecial forms

Macros have I feel the biggest role in terms of the hidden aspects. We do understand that a #'vector or #'+ are functions however and is not that obvious.

and is just a macro expanding to a bunch of if statements, (and x y z) becomes (if (if x y) z).

Even definitions aren't safe, in a simplified way (defun foo (x) x) expands to (setf (symbol-function 'foo) (lambda (x) x)). And of course defmacro is also just a macro setting macro.

defstruct is obvious, it expands to functions that register the type.

setf is magical as it runs everything up to the n - 1th step and then instead expands to the (setf ...) bound function to set the resulting place. So (setf (caaar x) 2) would expand along the lines of (rplaca (caar x) 2).

On that note (incf x) is just (setq x (+ 1 x)).

Common Lisp doesn't have built-in for-loops, it doesn't need them, loop is a famous macro which for things like (loop :for i :to 10 :do (print i)) generates:

(block nil
  (let ((i 0))
    (tagbody
     next
       (when (> i 10) (go end))
       (print i)
       (incf i)
       (go next)
     end)))

Obviously simplifying, as there are some optimizing constructs in play and many declarations are made to aid efficiency.

The entire object system is a library, control flow is mostly a library, isn't it beautiful?

The great advantage of this is that when you don't understand a construct, you don't have to inspect the binary of the compiler, for the most part desugared Lisp is your assembly in which you can view the world and to which you compile your programs with the help of macros.