% !TEX program = xelatex
\documentclass[10pt,letterpaper,twocolumn]{article}

\usepackage[top=0.75in, bottom=0.75in, left=0.75in, right=0.75in]{geometry}
\usepackage{fontspec}
\usepackage{unicode-math}
\setmainfont{Latin Modern Roman}
\setsansfont{Latin Modern Sans}
\newfontfamily\acbold{ywft-processing-bold}[Path=../../system/public/type/webfonts/,Extension=.ttf]
\newfontfamily\aclight{ywft-processing-light}[Path=../../system/public/type/webfonts/,Extension=.ttf]
\newfontfamily\kidlispfont{ComicRelief-Regular}[
  Path=../arxiv-kidlisp/fonts/,
  Extension=.ttf
]
\newfontfamily\kidlispbold{ComicRelief-Bold}[
  Path=../arxiv-kidlisp/fonts/,
  Extension=.ttf
]
\setmonofont{Latin Modern Mono}[Scale=0.85]

\usepackage{xcolor}
\usepackage{titlesec}
\usepackage{enumitem}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{multicol}
\usepackage{fancyhdr}
\usepackage{hyperref}
\usepackage{graphicx}
\graphicspath{{figures/}{../../papers/arxiv-ac/figures/}}
\usepackage{ragged2e}
\usepackage{microtype}
\usepackage{listings}
\usepackage{natbib}
\usepackage[colorspec=0.92]{draftwatermark}

% === COLORS ===
\definecolor{acpink}{RGB}{180,72,135}
\definecolor{acpurple}{RGB}{120,80,180}
\definecolor{acdark}{RGB}{64,56,74}
\definecolor{acgray}{RGB}{119,119,119}
\definecolor{klbrand}{RGB}{205,92,155}    % kidlisp.com primary (--ac-purple)
\definecolor{klcyan}{RGB}{112,214,255}     % kidlisp.com ".com" cyan (#70D6FF)
\definecolor{kldark}{RGB}{48,43,58}        % kidlisp.com dark purple
\definecolor{draftcolor}{RGB}{205,92,155}

% KidLisp syntax colors
\definecolor{klparen}{RGB}{140,140,160}
\definecolor{klkw}{RGB}{119,51,170}
\definecolor{klfn}{RGB}{0,136,170}
\definecolor{klcolor}{RGB}{204,80,0}
\definecolor{klnum}{RGB}{204,0,102}
\definecolor{klstr}{RGB}{44,145,44}
\definecolor{klcmt}{RGB}{140,140,140}
\definecolor{klvar}{RGB}{50,50,50}
\definecolor{klspecial}{RGB}{180,72,135}
\definecolor{klbg}{RGB}{250,248,252}

\DraftwatermarkOptions{text=WORKING DRAFT,fontsize=3cm,color=draftcolor!18,angle=45}

\hypersetup{colorlinks=true,linkcolor=acpurple,urlcolor=acpurple,citecolor=acpurple,
  pdftitle={KidLisp Language Reference: 118 Built-ins in 12 Categories}}

\titleformat{\section}{\normalfont\bfseries\normalsize\uppercase}{\thesection.}{0.5em}{}
\titlespacing{\section}{0pt}{1.2em}{0.3em}
\titleformat{\subsection}{\normalfont\bfseries\small}{\thesubsection}{0.5em}{}
\titlespacing{\subsection}{0pt}{0.8em}{0.2em}

\pagestyle{fancy}\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\fancyhead[C]{\footnotesize\color{acpink}\textit{Working Draft --- not for citation}}
\fancyfoot[C]{\footnotesize\thepage}

\newcommand{\ac}{\textsc{Aesthetic.Computer}}
% Random caps for Aesthetic.Computer branding
\newcount\acrandtmp
\newcommand{\acrandletter}[2]{%
  \acrandtmp=\uniformdeviate 2\relax
  \ifnum\acrandtmp=0\relax#1\else#2\fi%
}
\newcommand{\acrandname}{%
  \acrandletter{a}{A}\acrandletter{e}{E}\acrandletter{s}{S}\acrandletter{t}{T}%
  \acrandletter{h}{H}\acrandletter{e}{E}\acrandletter{t}{T}\acrandletter{i}{I}%
  \acrandletter{c}{C}{\color{acpink}.}\acrandletter{c}{C}\acrandletter{o}{O}%
  \acrandletter{m}{M}\acrandletter{p}{P}\acrandletter{u}{U}\acrandletter{t}{T}%
  \acrandletter{e}{E}\acrandletter{r}{R}%
}
\newcommand{\kl}{\textsc{KidLisp}}

% === KIDLISP LISTING STYLE ===
\lstdefinelanguage{kidlisp}{
  morekeywords=[1]{def,if,repeat,once,later,die,let,do,fn},
  morekeywords=[2]{wipe,ink,line,box,circle,tri,plot,flood,shape,write,type,paste,print},
  morekeywords=[3]{scroll,zoom,spin,blur,contrast,suck,pan,sort,resetSpin,smoothspin,unpan,fill,outline,stroke,nofill,nostroke},
  morekeywords=[4]{random,wiggle,sin,cos,tan,floor,ceil,round,abs,sqrt,min,max,mod},
  morekeywords=[5]{width,height,frame,time,resolution,fps,screen,pen,hand,gamepad,mic,amplitude},
  morekeywords=[6]{cube,form,trans,move,scale,hop,delay,jump,melody,overtone,speaker,sound},
  morekeywords=[7]{embed,layer,fade,bake,list,get,set,tap},
  sensitive=true,
  morecomment=[l]{;},
  morestring=[b]",
  literate=
    {(}{{{\color{klparen}(}}}1
    {)}{{{\color{klparen})}}}1
    {\$}{{{\color{klspecial}\$}}}1,
}

\lstdefinestyle{kidlispstyle}{
  language=kidlisp,
  basicstyle=\ttfamily\small,
  keywordstyle=[1]\color{klkw}\bfseries,
  keywordstyle=[2]\color{klfn}\bfseries,
  keywordstyle=[3]\color{acpurple},
  keywordstyle=[4]\color{klnum},
  keywordstyle=[5]\color{klspecial},
  keywordstyle=[6]\color{klfn},
  keywordstyle=[7]\color{acpink},
  commentstyle=\color{klcmt}\itshape,
  stringstyle=\color{klstr},
  numberstyle=\tiny\color{klcmt},
  breaklines=true,
  frame=single,
  rulecolor=\color{acgray!30},
  backgroundcolor=\color{klbg},
  xleftmargin=0.5em,
  xrightmargin=0.5em,
  aboveskip=0.5em,
  belowskip=0.5em,
  showstringspaces=false,
}

\lstset{style=kidlispstyle}

\setlist[itemize]{nosep, leftmargin=1.2em, itemsep=0.1em}
\setlength{\columnsep}{1.8em}
\setlength{\parindent}{1em}
\setlength{\parskip}{0.3em}

% Hyphenation for narrow two-column layout
\tolerance=800
\emergencystretch=1em
\hyphenpenalty=50

\begin{document}

\twocolumn[{%
\begin{center}
\includegraphics[height=4em]{pals}\par\vspace{0.5em}
{\kidlispbold\fontsize{26pt}{30pt}\selectfont\color{kldark} Kid{\color{klbrand}Lisp} Language Reference}\par
\vspace{0.2em}
{\kidlispfont\fontsize{11pt}{13pt}\selectfont\color{klbrand} 118 Built-ins in 12 Categories for Generative Art}\par
\vspace{0.3em}
{\kidlispfont\fontsize{9pt}{11pt}\selectfont\color{acgray} Syntax, Semantics, Timing, Color, and the \texttt{\$}-Code Composition System}\par
\vspace{0.6em}
{\normalsize\href{https://prompt.ac/@jeffrey}{@jeffrey}}\par
{\small\color{acgray} Aesthetic.Computer}\par
{\small\color{acgray} ORCID: \href{https://orcid.org/0009-0007-4460-4913}{0009-0007-4460-4913}}\par
\vspace{0.3em}
{\small\color{acpurple} \url{https://aesthetic.computer}}\par
\vspace{0.6em}
\rule{\textwidth}{1.5pt}
\vspace{0.5em}
\end{center}

\begin{center}
{\small\color{acpink}\textbf{[ working draft --- not for citation ]}}
\end{center}
\vspace{0.3em}

\begin{quote}
\small\noindent\textbf{Abstract.}
\kl{} is a minimal Lisp dialect for generative art with 118 built-in functions across 12 categories, no user-defined functions, no recursion, no file I/O, and no networking. It is safe by construction: a \kl{} program cannot break out of its sandbox, crash its host, or access resources beyond its canvas. This paper serves as a complete language reference, documenting every built-in function with syntax-highlighted examples, the timing system (frame-based and second-based scheduling without callbacks), the color model (named colors, RGB, gradients, patterns), the \texttt{\$}-code composition system (embedding programs by reference as the primary abstraction mechanism), and the evaluation model (full AST re-evaluation every frame with deterministic PRNG). We present \kl{} as a language designed around \emph{omission}: what it cannot do is as deliberate as what it can, and the constraints produce a creative space that 59 authors have used to write 16,634 programs.
\end{quote}
\vspace{0.5em}
}]

\section{Syntax}

\kl{} uses S-expression syntax~\citep{mccarthy1960recursive}. Every expression is either an atom (number, string, symbol) or a list enclosed in parentheses:

\begin{lstlisting}
; Atoms
42                    ; number
"hello"               ; string
red                   ; symbol (color name)

; Lists (function application)
(wipe "navy")         ; clear screen navy
(ink "red")           ; set drawing color
(box 10 10 50 50)     ; draw rectangle
(circle 64 64 30)     ; draw circle
\end{lstlisting}

There are no operators, no infix notation, no special syntax beyond parentheses, strings, numbers, and symbols. Arithmetic uses prefix notation:

\begin{lstlisting}
(+ 1 2)              ; => 3
(* 3 (+ 1 2))        ; => 9
(- 10 3)             ; => 7
(/ 100 4)            ; => 25
(% 17 5)             ; => 2 (modulo)
\end{lstlisting}

\section{The 12 Categories}

\subsection{Graphics (9 functions)}

Drawing primitives operate in immediate mode---each call renders directly to the framebuffer.

\begin{lstlisting}
(wipe "black")        ; clear canvas
(ink "cyan")          ; set color
(line 0 0 128 128)    ; diagonal line
(box 10 10 40 40)     ; rectangle
(circle 64 64 20)     ; circle at center
(tri 32 10 10 54 54 54) ; triangle
(plot 64 64)          ; single pixel
(flood 64 64)         ; flood fill
(shape 10 10 50 10 30 50) ; polygon
\end{lstlisting}

\texttt{fill} and \texttt{outline} control whether shapes are solid or stroked (Processing-compatible):

\begin{lstlisting}
(fill)                ; filled shapes
(ink "red")
(circle 64 64 30)     ; solid red circle

(outline)             ; outlined shapes
(ink "white")
(circle 64 64 30)     ; white ring
\end{lstlisting}

\subsection{Transformations (11 functions)}

Pixel-level transformations operate on the framebuffer after drawing:

\begin{lstlisting}
(scroll 1 0)          ; shift pixels right
(zoom 1.01)           ; slow zoom in
(spin 1)              ; rotate 1 degree
(blur 2)              ; gaussian blur
(contrast 1.2)        ; increase contrast
(suck 0.5)            ; radial displacement
(sort)                ; sort pixels by brightness
\end{lstlisting}

Transformations \emph{accumulate} across frames, producing animation without explicit state management:

\begin{lstlisting}
(wipe "black")
(ink "white")
(circle 64 64 10)     ; draw circle
(spin 2)              ; rotate 2 deg/frame
(zoom 1.005)          ; grow slightly/frame
; Result: spiraling, growing circle
\end{lstlisting}

\subsection{Math (14 functions)}

\begin{lstlisting}
(sin (* frame 0.05))  ; sine wave
(cos (* frame 0.03))  ; cosine wave
(random)              ; 0-255
(random 10)           ; 0-9
(random 5 15)         ; 5-14
(wiggle 10)           ; random +/-5
(floor 3.7)           ; => 3
(abs -5)              ; => 5
(sqrt 16)             ; => 4
(min 3 7 1)           ; => 1
(max 3 7 1)           ; => 7
\end{lstlisting}

\texttt{random} uses a seeded PRNG initialized from the program's short code, making all generative output \textbf{deterministic}: the same program always produces the same visual.

\subsection{Color (19+ named colors)}

Colors can be specified as names, RGB values, or gradient strings:

\begin{lstlisting}
(ink "red")           ; named color
(ink 255 0 0)         ; RGB
(ink 255 0 0 128)     ; RGBA (semi-transparent)
(ink "fade:red-blue") ; horizontal gradient
(ink (fade "cyan" "magenta" "vertical"))
(ink "rainbow")       ; repeating rainbow
(ink "zebra")         ; striped pattern
\end{lstlisting}

Available color names include all CSS named colors: \texttt{red}, \texttt{green}, \texttt{blue}, \texttt{yellow}, \texttt{orange}, \texttt{purple}, \texttt{pink}, \texttt{cyan}, \texttt{magenta}, \texttt{black}, \texttt{white}, \texttt{gray}, \texttt{brown}, \texttt{lime}, \texttt{navy}, \texttt{teal}, \texttt{gold}, \texttt{coral}, \texttt{salmon}, \texttt{crimson}, \texttt{lavender}, \texttt{indigo}, \texttt{violet}, \texttt{turquoise}, \texttt{tomato}, and more.

A bare color name on the first line sets the background:

\begin{lstlisting}
"navy"
(ink "gold")
(circle 64 64 30)
; Navy background, gold circle
\end{lstlisting}

\subsection{System \& Display (9 functions)}

\begin{lstlisting}
(def w width)         ; screen width
(def h height)        ; screen height
frame                 ; current frame number
time                  ; seconds elapsed

(resolution "half")   ; half-resolution
(resolution 64 64)    ; explicit 64x64
(fps 30)              ; set frame rate
\end{lstlisting}

\subsection{Control Flow (7 functions)}

\begin{lstlisting}
; Variable definition
(def x 50)
(def y (+ 10 (* frame 0.5)))

; Conditional
(if (> frame 60)
  (ink "red")
  (ink "blue"))

; Loop
(repeat 10 i
  (circle (* i 12) 64 5))

; Execute once (not every frame)
(once (wipe "black"))

; Local binding
(let ((cx 64) (cy 64))
  (circle cx cy 30))
\end{lstlisting}

The \texttt{repeat} loop binds its counter variable (\texttt{i} above) from 0 to $n-1$. Nested repeats use different variable names:

\begin{lstlisting}
(repeat 8 i
  (repeat 8 j
    (box (* i 16) (* j 16) 14 14)))
; 8x8 grid of squares
\end{lstlisting}

\subsection{Timing}

\kl{}'s timing system uses \emph{inline scheduling} rather than callbacks. Timing expressions wrap code blocks:

\begin{lstlisting}
; Frame-based timing
(0 (wipe "black"))    ; every frame
(1 (spin 5))          ; every 2nd frame
(30f (ink "red"))     ; after 30 frames

; Second-based timing
(1s (wipe "red"))     ; after 1 second
(2.5s (ink "gold"))   ; after 2.5 seconds
(1s! (write "!" 10 10)) ; fire once at 1s

; Repeating intervals
(0.5s... (spin 45))   ; every 0.5 seconds
(1s... (scroll 1 0))  ; every second
\end{lstlisting}

This eliminates the need for \texttt{setTimeout}, \texttt{setInterval}, or animation frame callbacks. Time is a \emph{property of the expression}, not a function called on it.

\subsection{Text (4 functions)}

\begin{lstlisting}
(write "hello" 10 20) ; text at position
(write "centered"     ; centered text
  (/ width 2) (/ height 2))
(type "typed" 10 10)  ; typewriter effect
\end{lstlisting}

\subsection{Input (3 functions)}

\begin{lstlisting}
; Pen/mouse position and state
(if pen
  (circle pen.x pen.y 5))

; Touch input
(if hand
  (line hand.x hand.y 64 64))
\end{lstlisting}

\subsection{Audio (6 functions)}

\begin{lstlisting}
; Microphone input
(def vol (mic))       ; amplitude 0-255
(circle 64 64 vol)    ; sound-reactive

; Melody playback
(melody "C4 E4 G4 C5")

; Overtone harmonics
(overtone 440 3)      ; 3rd harmonic of A4
\end{lstlisting}

\subsection{3D Graphics (8 functions)}

\begin{lstlisting}
(cube "mycube")       ; create 3D cube
(form "mycube"
  (move 0 0 -5)       ; position
  (scale 2)           ; size
  (spin (* frame 0.5) 1 1 0)) ; rotate
\end{lstlisting}

\subsection{Composition via \texttt{\$}-Codes}

The most distinctive feature of \kl{} is its composition system. Instead of user-defined functions, programs reference other programs by their short code:

\begin{lstlisting}
; Embed another program as a layer
($cow)                ; execute program "cow"
($nece 10 20)         ; pass parameters

; Multi-layer composition
(wipe "black")
($cow)                ; background layer
($faim)               ; foreground layer

; Chain multiple programs
(resolution 64 64)
($zobi)
(spin 1)
($grel)
\end{lstlisting}

Programs are fetched from MongoDB, cached in RAM and IndexedDB, and content-addressed via SHA-256. The \texttt{\$}-code system replaces user-defined functions, modules, and libraries with a single social mechanism: \emph{find a program someone made, reference it by code, compose with it}.

The most-referenced programs are simple visual primitives that serve as building blocks. The system produces a social dependency graph: program A embeds program B, which embeds program C, up to 7 layers deep in observed usage.

\section{Evaluation Model}

\kl{} re-evaluates its \textbf{entire AST every frame}. There is no retained state beyond explicitly defined variables. The \texttt{frame} and \texttt{time} variables increment automatically. Transformations like \texttt{zoom}, \texttt{scroll}, and \texttt{spin} accumulate in the framebuffer.

This model eliminates the \texttt{setup()}/\texttt{draw()} split familiar from Processing~\citep{reas2007processing}. Every line of a \kl{} program executes every frame. Animation emerges from frame-dependent expressions:

\begin{lstlisting}
(wipe "black")
(ink "white")
; Circle orbits center using sin/cos
(circle
  (+ 64 (* 30 (cos (* frame 0.03))))
  (+ 64 (* 30 (sin (* frame 0.03))))
  8)
\end{lstlisting}

\subsection{Deterministic Randomness}

\texttt{random} is seeded from the program's short code. The same program produces identical output on every device, every time. This makes \kl{} programs \emph{reproducible generative art}: the code \emph{is} the artwork, not just the instructions for generating it.

\subsection{Chaos Mode}

Invalid input---gibberish, unbalanced parentheses, random characters---does not produce error messages. Instead, \kl{} detects low recognition ratios ($<30\%$ known words) and high special character ratios ($>50\%$) and renders artistic visual output. The user never sees ``SyntaxError.'' They see colors.

\section{Design by Omission}

\kl{} deliberately lacks:

\begin{itemize}
  \item \textbf{User-defined functions}: replaced by \texttt{\$}-code composition
  \item \textbf{Recursion}: prevents infinite loops and stack overflows
  \item \textbf{File I/O}: the canvas is the only output
  \item \textbf{Networking}: programs cannot fetch external data
  \item \textbf{String manipulation}: no \texttt{concat}, \texttt{split}, \texttt{replace}
  \item \textbf{Error messages}: replaced by chaos mode
  \item \textbf{Import/require}: replaced by \texttt{\$}-codes
  \item \textbf{Objects/classes}: data is numbers, strings, and lists
\end{itemize}

Each omission is a design decision. The absence of user-defined functions forces composition through the social layer. The absence of error messages means beginners never encounter a wall of red text. The absence of networking means every program is self-contained and safe to run.

This follows the principle that a language's constraints define its creative space more than its features~\citep{papert1980mindstorms, compton2015casual}. \kl{} is not a general-purpose language that happens to do art. It is an art language that \emph{cannot} do anything else.

\section{Complete Built-in Index}

\begin{table}[h]
\small
\centering
\begin{tabularx}{\columnwidth}{Xlr}
\toprule
\textbf{Category} & \textbf{Count} & \textbf{Core Functions} \\
\midrule
Graphics & 9 & wipe, ink, line, box, circle \\
Transformations & 11 & scroll, zoom, spin, blur, suck \\
Math & 14 & +, -, *, /, random, sin, cos \\
Color & 19+ & red, blue, fade, rainbow, zebra \\
System/Display & 9 & width, height, frame, time \\
Control Flow & 7 & def, if, repeat, once, let \\
Text/Output & 4 & write, type, paste, print \\
Input & 3 & pen, hand, gamepad \\
Audio & 6 & mic, melody, overtone, sound \\
3D Graphics & 8 & cube, form, trans, move, scale \\
Composition & 4 & \$code, layer, bake, embed \\
Data & 4 & list, get, set, let \\
\midrule
\textbf{Total} & \textbf{118} & \\
\bottomrule
\end{tabularx}
\caption{All 118 built-in functions by category.}
\label{tab:builtins}
\end{table}

\section{Example: Complete Program}

A complete \kl{} program that draws a sound-reactive particle field with orbital motion:

\begin{lstlisting}
"black"
(def vol (+ 5 (* (mic) 0.2)))
(repeat 50 i
  (def angle (* i 0.1256))
  (def r (+ 20 (* vol (sin (+ (* frame 0.02) angle)))))
  (def cx (+ 64 (* r (cos (+ angle (* frame 0.01))))))
  (def cy (+ 64 (* r (sin (+ angle (* frame 0.01))))))
  (ink (+ 100 (* i 3)) 50 (+ 150 (* i 2)))
  (circle cx cy (+ 1 (random 3))))
(blur 1)
(zoom 1.002)
\end{lstlisting}

This program: sets a black background, reads microphone amplitude, draws 50 particles in orbital paths modulated by sound, colors them with a computed gradient, applies a slight blur, and slowly zooms in. It runs at 60 FPS. It is 12 lines long. It requires no imports, no setup function, no animation loop, and no event listeners.

\vspace{0.5em}
\noindent\textbf{ORCID:} \href{https://orcid.org/0009-0007-4460-4913}{0009-0007-4460-4913}

\bibliographystyle{plainnat}
\bibliography{references}

\end{document}
