tinylisp is, in its essence, a very stripped-down version of Lisp, as the name suggests. It was made by @DLosc for an "interpret this language" challenge, which can be found here. It features a small amount of builtins, which can be used to create practically anything.

There is a repository for the "official" tinylisp interpreter/documentation here, and it is available to try online here.

What tips do you have for golfing (creating the shortest program possible) in tinylisp? This question is looking for tips to golf specifically in tinylisp, not general tips that can be applied to any language.


Use lambdas instead of full functions

To save a few bytes, you can make your answer a lambda instead of a full function:

Predecessor function:
(q (
  (s n 1)))

(q((n)(s n 1)))

This is only useful if the function doesn't recurse.


Use the library

Although tinylisp itself has a small set of builtins, it also comes with a standard library that adds a lot of functionality. You can access any function in the library by running (load library).

The names of library functions/constants are not golfy like the builtins are, so some of them aren't worth it. For example, there's no need to load the library just to use inc or dec, since (a 1 x) is the same length as (inc x) and (a(some-expr)1) is shorter than (inc(some-expr)). For others, it depends on the use case: using reverse is probably shorter than reimplementing it yourself, but you may be able to restructure your code to avoid using it at all. Others, like *, are indispensable (multiplication isn't built in, and reimplementing it would be prohibitively long).

One drawback: there's not really any documentation besides just reading the code.


Take advantage of parenthesis autocompletion

The tinylisp parser will fill in missing close parens at the end of each line, provided that each of your top-level expressions is on a single line (which it should be anyway for code golf). So instead of this:

(load library)(d D(q((M)(i(h M)(c(h(h M))(D(map t(t M))))()))))

you can write this, for a savings of 5 bytes:

(load library
(d D(q((M)(i(h M)(c(h(h M))(D(map t(t M))))(

(Just make sure that your test code in the header or footer is formatted the same way, or you may get some puzzling error messages.)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.