tl;dr: Imaginary Programming (IP) is where
data and knowledge has been substituted for
inference by a LM. Therefore, the
implementation of an 𝑖λ library will be
uniquely tailored to each language.
I design and build an IP library named
𝑖λ.el for emacs. Think of it a bit like a
functional programming library in that you
will find a set of functions and macros for
working in the programming paradigm. The
objective here is to create some functions for
doing IP in emacs lisp, since emacs lisp has
the expressive power to prototype such things,
but the ideas contained here can easily be
transferred to any other programming language.
The results of this little experiment will go
straight into my thesis.
imacro (like regular macros) are for
generating code. idefun, however, doesnt
generate the code but attempts to evaluate a
function without code, or if code is supplied
then imagine evaluating that code rather than
actually evaluating it.
It’s kinda crazy that Im-macros run faster
and are more reliable than Im-functions,
where the opposite is true in regular
programming. That’s because they generate the
code which can be reused, adjusted and
interactively regenerated, where an
Im-function will typically have to query the
LM every time you call it.
The objective with 𝑖λ.el
The objective here is to create IP functions
for programming in emacs lisp exclusively.
It will be extended in the future to do all
programming languages, but I intend to make
𝑖λ.el simple and effective for programming
in emacs lisp without bloat or over-complication.
ieval will imagine the evaluation of some code without any other context.
imacro does not evaluate. It merely generates code, but that code is imagined. Like idefun it is variadic.
ieval and imacro
Run an imagined function on the given arguments and return an imagined result, but create a binding for the function.
Generate a list of things. Return a real list.
ilambda / 𝑖λ
Imaginarily run an expression on the given arguments and return an imagined result.
Imaginarily filter a real list with natural language and return a real list. Optionally, enforce cardinality.
Given a syntax form / expression, will parse a syntax form with natural language. Returns the subform.
Select the appropriate imacro/N form depending on the arity of arguments.
ieval will simply evaluate the provided
string/sexp as emacs lisp code. You
must provide ieval with, firstly, the preceding
code, which may be, for example, a function
definition or package requires, etc. and,
secondly, evaluated expression. Either
argument can either be a raw string containing
code or a sexp, but the expression will be
“one-line-ized” for the prompt.
(-reduce (𝑖λ (x y) "add x to y") (number-sequence 13))
The idefun creates a binding to an imaginary
function. The implementation of the idefun
need not be specified in order for code to
The new prompt function returned by idefun is provided with arguments and the
values of those arguments are taken and placed
into a prompt. An implementation may be
provided to idefun when defining the prompt function or optionally left out.
Unlike an imacro, when the prompt function
is evaluated the code is not returned. Rather,
the code is evaluted in imaginary space.
In short, the LM will imagine the evaluation
of the function as opposed to generate code.
idefun returns a binding to a new prompt
(idefun add-two-numbers (a b))
(idefun add-two-numbers (a b) "add a to b")
(idefun add-two-numbers (a b) "add a to b")
title: imagine an emacs functiontask: "imagine an emacs lisp function given name, arguments and docstring"doc: "Given a function name, arguments and docstring, return the imagined body of the function"prompt-version: 1prompt: |+ ;;my-emacs-library.el
(defun <name> (<arguments>)
"<docstring>"engine: "OpenAI Codex"temperature: 0.2max-generated-tokens: 1000top-p: 1.0cache: onstop-sequences:
- "docstring"validator: "chomp | sed -z 's/.*\\(.\\)$/\\1/' | grep -q ')'"examples:
- "x y"
- "multiply two numbers and return a number"preprocessors:
- "slugify"postprocessor: chomppostpostprocessor: "sed -z \"s/^;;my-emacs-library.el\\\\n\\\\n//\""filter: oncompletion: offinsertion: off
"times""x y""multiply two numbers and return a number"
(defun times (x y)
"multiply two numbers and return a number"
(* x y))
There are 3 different versions of imacro
depending on how many arguments are supplied to
All of the following are valid ways to invoke defimacro.
defimacro selects the right imacro/N function depending on the arity of the arguments.
(defimacro my/subtract (a b c))
(defimacro my/itimes (a b c)
"multiply three complex numbers")
The easiest of the list of syntax forms I
aimed to implement, ilist simply takes a the
number of items to generate (n) and a string
describing the type of thing to generate
(type-of-thing). It will return a real list
of such things.