λ
(Imaginary Programming Functions)
Summary
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.
- λ project
- http://github.com/semiosis/ilambda/
- IP thesis
- https://github.com/semiosis/imaginary-programming-thesis/blob/master/thesis.org
- IP library
- http://github.com/semiosis/pen.el/blob/master/src/ilambda.el
- Glossaries
- Imaginary Programming ⚔ Pen.el ⚔ Prompt Engineering ⚔ Epistemology
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.
Syntax forms
name | type | depends on | basic idea |
---|---|---|---|
ieval |
MACRO | ieval will imagine the evaluation of some code without any other context. |
|
imacro/N |
MACRO | imacro does not evaluate. It merely generates code, but that code is imagined. Like idefun it is variadic. |
|
idefun |
FUNCTION | ieval and imacro |
Run an imagined function on the given arguments and return an imagined result, but create a binding for the function. |
ilist |
FUNCTION | Generate a list of things. Return a real list. | |
ilambda / λ |
FUNCTION | ieval |
Imaginarily run an expression on the given arguments and return an imagined result. |
ifilter |
FUNCTION | Imaginarily filter a real list with natural language and return a real list. Optionally, enforce cardinality. | |
iparse |
MACRO | Given a syntax form / expression, will parse a syntax form with natural language. Returns the subform. | |
defimacro |
MACRO | imacro/N |
Select the appropriate imacro/N form depending on the arity of arguments. |
ieval
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.
ieval
is used by idefun
and ilambda
.
prompt function for running the eval.
pf-imagine-evaluating-emacs-lisp/2
- http://github.com/semiosis/prompts/blob/master/prompts/imagine-evaluating-emacs-lisp-2.prompt
|
|
The following is the implementation of ieval
.
You may pass either a sexp
or a raw string containing code.
|
|
|
|
Resulting prompt from test-ieval-2
:
|
|
ieval
not only evaluates correctly despite
the deliberately incorrect naming of the
function (it multiplies rather than doubles),
but it returns the value as the correct data type.
|
|
Expansion of test-ieval
.
|
|
ilambda
/ λ
Imaginarily run an expression on the given
arguments and return an imagined result.
Here are three ilambda
subforms which take different arguments.
ilambda/task
is the most terse. Only a NL
task description is given.
|
|
Demonstrations
|
|
|
|
|
|
The ilambda macro.
|
|
|
|
idefun
The idefun
creates a binding to an imaginary
function. The implementation of the idefun
need not be specified in order for code to
run.
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
function.
Some examples:
|
|
|
|
With a temperature of 0.0
, this will hash to
the same thing every time!
Strangely, we can’t call it a ’neural hash’ though.
|
|
|
|
|
|
“0x7f8b8f8e”
|
|
|
|
I have no idea if this data is correct but it
seems consistent with itself.
|
|
Sadly, Codex doesn’t know too much about Scoville food hotness.
food | Scoville scale |
---|---|
Pure capsaicin | 16,000,000 SHU |
Jalapeño | 10,000 SHU |
|
|
|
|
|
|
Demo
imacro
An imacro
actually imagines the
implementation of a function.
Components of the imacro
should be inferred.
An imacro
with only a function name should
work.
Also, an imacro
is under the hood a regular
macro. This means, that expanding the imacro
will infer/generate underlying code.
|
|
|
|
|
|
pf-imagine-an-emacs-function/3
- http://github.com/semiosis/prompts/blob/master/prompts/imagine-an-emacs-function-3.prompt
|
|
|
|
|
|
There are 3 different versions of imacro
depending on how many arguments are supplied to
it.
|
|
|
|
|
|
imacro
expansion demo
|
|
|
|
|
|
defimacro
|
|
All of the following are valid ways to invoke defimacro
.
defimacro
selects the right imacro/N
function depending on the arity of the arguments.
|
|
ilist
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.
|
|
ifilter
ifilter
takes
Example:
|
|
|
|
itest
|
|
|
|
Derived functions
iparse
itransform
|
|
|
|
TODO Pure imaginary syntax forms
name |
---|
imaginary comparator |