Cons Is Basically Goto

cons is really low level construct used in some lisps. It's too low level and it affects the rest of the language.

what is cons?

For the purpose of this article, cons is a function that takes two arbitrary values and returns a cons cell. In other words, it's a tuple.

what does it enable?

cons is really general purpose. You can build lists, trees and even key-value stores ('association lists').

This is great if you want a minimal language. An "ur lisp", a "lisp 1.5" or a "maxwell's law of equations lisp" can be built with cons.

why is it like goto?

It can be abused for too many different purposes.

Try writing the map function in Scheme. map should take a list, apply a function f to every item, and return the result.

This is surprisingly hard to get right:

  • Do you handle improper lists (cons 1 2)?
  • Do you use constant stack space with TCO?