Using AND with the apply function in Scheme

and isn’t a normal function because it will only evaluate as few arguments as it needs, to know whether the result is true or false. For example, if the first argument is false, then no matter what the other arguments are, the result has to be false so it won’t evaluate the other arguments. If … Read more

What exactly is a symbol in lisp/scheme?

In Scheme and Racket, a symbol is like an immutable string that happens to be interned so that symbols can be compared with eq? (fast, essentially pointer comparison). Symbols and strings are separate data types. One use for symbols is lightweight enumerations. For example, one might say a direction is either ‘north, ‘south, ‘east, or … Read more

How many primitives does it take to build a LISP machine? Ten, seven or five?

Basic Predicates/F-functions McCarthy‘s Elementary S-functions and Predicates were: atom Which was necessary because car and cdr are defined for lists only, which means you cannot count on any sort of answer to indicate what was happening if you gave car an atom. eq For testing equality between atoms. car For returning the first half (address) … Read more

Flatten a list using only the forms in “The Little Schemer”

I have a version that uses only “first-principles” operations and is efficient (does not require more than one pass through any of the lists, unlike append-based solutions). 🙂 It does this by defining two simple building blocks (fold and reverse), and then defining flatten (and its helper, reverse-flatten-into) atop those (and notice how each function … Read more

What is “point free” style (in Functional Programming)?

Just look at the Wikipedia article to get your definition: Tacit programming (point-free programming) is a programming paradigm in which a function definition does not include information regarding its arguments, using combinators and function composition […] instead of variables. Haskell example: Conventional (you specify the arguments explicitly): sum (x:xs) = x + (sum xs) sum … Read more