In this post, I am going to show you how to write programs that are self-referential. By self-referential, I mean programs which are able to obtain their own source code without any external input. In other words, they won’t just … Read the rest
Category: Basic Macros
These are basic Lisp macros that should be trivial to understand.
Loops in Lisp Part 1: Goto
At its core, Common Lisp provides two primitives for performing iteration. The first of those primitives is recursion. Recursion is an amazing technique, but in this post I am going to focus on the other primitive goto.
Goto is extremely … Read the rest
Defmemo
In my last post I talked about memoization i.e. caching the results of a function. Memoization is a fairly common technique for optimization. It is common enough to warrant writing a macro that makes it easy to define memoized functions. … Read the rest
Zap
This post makes use of places. If you are unfamiliar with how places work, see my post Getting Places.
Many languages provide syntactic sugar for evaluating an expression involving a variable and assigning the result of that expression to … Read the rest
Multiple-value-bind
Common Lisp is a pretty unique language. One of the many features that makes Common Lisp such an awesome language is multiple values. Yes, you read right. In Common Lisp it is possible for a function to return more than … Read the rest
Hofeach
Last time I talked about mapeach, a macro which is a simple wrapper around mapcar. After using mapeach a couple times, I found that I wanted each version of many other other functions, remove, find, and … Read the rest
Mapeach
Many times when using mapcar, I find myself using a complex lambda expression for the function argument. This makes the code difficult to read since it breaks apart the flow. My code winds up looking like the following:
First … Read the rest
Automatically Binding Gensyms
One of the most common macros that almost everyone keeps in their utilities file is with-gensyms. With-gensyms is a macro that binds a list of variables to gensyms. Thats it! All with-gensyms does it take a list of symbols … Read the rest
The Ret Macro
The ret macro is simple, but useful. It allows you to bind a variable and simultaneously specify the final value of that variable as the result of the ret expression, hence the name ret, a blend of let and return… Read the rest