\doxysection{loop.\+c}
\hypertarget{loop_8c_source}{}\label{loop_8c_source}\index{workspace/post-\/scarcity/src/ops/loop.c@{workspace/post-\/scarcity/src/ops/loop.c}}
\mbox{\hyperlink{loop_8c}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00001}00001\ \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00002}00002\ \textcolor{comment}{\ *\ loop.c}}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00003}00003\ \textcolor{comment}{\ *}}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00004}00004\ \textcolor{comment}{\ *\ Iteration\ functions.\ This\ has\ *a\ lot*\ of\ similarity\ to\ try/catch\ -\/-\/\ }}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00005}00005\ \textcolor{comment}{\ *\ essentially\ what\ \`{}recur`\ does\ is\ throw\ a\ special\ purpose\ exception\ which\ is}}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00006}00006\ \textcolor{comment}{\ *\ caught\ by\ \`{}loop`.}}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00007}00007\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00008}00008\ \textcolor{comment}{\ *\ Essentially\ the\ syntax\ I\ want\ is\ }}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00009}00009\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00010}00010\ \textcolor{comment}{\ *\ \ (defun\ expt\ (n\ e)}}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00011}00011\ \textcolor{comment}{\ *\ \ \ \ \ \ (loop\ ((n1\ .\ n)\ (r\ .\ n)\ (e1\ .\ e))}}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00012}00012\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ (cond\ ((=\ e\ 0)\ r)}}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00013}00013\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ (t\ (recur\ n1\ (*\ n1\ r)\ (-\/\ e\ 1)))))}}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00014}00014\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00015}00015\ \textcolor{comment}{\ *\ It\ might\ in\ future\ be\ good\ to\ allow\ the\ body\ of\ the\ loop\ to\ comprise\ many}}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00016}00016\ \textcolor{comment}{\ *\ expressions,\ like\ a\ \`{}progn`,\ but\ for\ now\ if\ you\ want\ that\ you\ can\ just}}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00017}00017\ \textcolor{comment}{\ *\ shove\ a\ \`{}progn`\ in.\ Note\ that,\ given\ that\ what\ \`{}recur`\ is\ essentially}}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00018}00018\ \textcolor{comment}{\ *\ doing\ is\ throwing\ a\ special\ purpose\ exception,\ the\ \`{}recur`\ expression}}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00019}00019\ \textcolor{comment}{\ *\ doesn't\ actually\ have\ to\ be\ in\ the\ same\ function\ as\ the\ \`{}loop`\ expression.}}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00020}00020\ \textcolor{comment}{\ *}}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00021}00021\ \textcolor{comment}{\ *\ (c)\ 2021\ Simon\ Brooke\ <simon@journeyman.cc>}}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00022}00022\ \textcolor{comment}{\ *\ Licensed\ under\ GPL\ version\ 2.0,\ or,\ at\ your\ option,\ any\ later\ version.}}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00023}00023\ \textcolor{comment}{\ */}}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00024}00024\ }
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00025}00025\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{consspaceobject_8h}{consspaceobject.h}}"{}}}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00026}00026\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{lispops_8h}{lispops.h}}"{}}}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00027}00027\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{loop_8h}{loop.h}}"{}}}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00028}00028\ \textcolor{comment}{}}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00029}00029\ \textcolor{comment}{/**}}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00030}00030\ \textcolor{comment}{\ *\ Special\ form,\ not\ dissimilar\ to\ \`{}let`.\ Essentially,}}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00031}00031\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00032}00032\ \textcolor{comment}{\ *\ 1.\ the\ first\ arg\ (`args`)\ is\ an\ assoc\ list;}}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00033}00033\ \textcolor{comment}{\ *\ 2.\ the\ second\ arg\ (`body`)\ is\ an\ expression.}}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00034}00034\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00035}00035\ \textcolor{comment}{\ *\ Each\ of\ the\ vals\ in\ the\ assoc\ list\ is\ evaluated,\ and\ bound\ to\ its\ }}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00036}00036\ \textcolor{comment}{\ *\ respective\ key\ in\ a\ new\ environment.\ The\ body\ is\ then\ evaled\ in\ that}}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00037}00037\ \textcolor{comment}{\ *\ environment.\ If\ the\ result\ is\ an\ object\ of\ type\ LOOP,\ it\ should\ carry\ }}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00038}00038\ \textcolor{comment}{\ *\ a\ list\ of\ values\ of\ the\ same\ arity\ as\ args.\ Each\ of\ the\ keys\ in\ args}}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00039}00039\ \textcolor{comment}{\ *\ is\ then\ rebound\ in\ a\ new\ environment\ to\ the\ respective\ value\ from\ the\ }}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00040}00040\ \textcolor{comment}{\ *\ LOOP\ object,\ and\ body\ is\ then\ re-\/evaled\ in\ that\ environment.}}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00041}00041\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00042}00042\ \textcolor{comment}{\ *\ If\ the\ result\ is\ not\ a\ LOOP\ object,\ it\ is\ simply\ returned.}}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00043}00043\ \textcolor{comment}{\ */}}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00044}00044\ \textcolor{keyword}{struct\ }\mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\_pointer}}}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00045}\mbox{\hyperlink{loop_8c_a3d25163fa4f49298b23e78557f915268}{00045}}\ \mbox{\hyperlink{loop_8c_a3d25163fa4f49298b23e78557f915268}{lisp\_loop}}(\ struct\ \mbox{\hyperlink{consspaceobject_8h_structstack__frame}{stack\_frame}}\ *frame,\ \textcolor{keyword}{struct\ }\mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\_pointer}}\ frame\_pointer,}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00046}00046\ \ \ \ \ \ \ \ \ \ \ \ struct\ \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\_pointer}}\ env\ )\ \{}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00047}00047\ \ \ \ \ \textcolor{keyword}{struct\ }\mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\_pointer}}\ keys\ =\ \mbox{\hyperlink{lispops_8c_a8e1a3da3aea36db9cf736ceb76046810}{c\_keys}}(\ frame-\/>arg[0]\ );}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00048}00048\ \ \ \ \ \textcolor{keyword}{struct\ }\mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\_pointer}}\ body\ =\ frame-\/>arg[1];}
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00049}00049\ }
\DoxyCodeLine{\Hypertarget{loop_8c_source_l00050}00050\ \}}

\end{DoxyCode}
