Post Scarcity
A prototype for a post scarcity programming environment
Loading...
Searching...
No Matches
loop.c
Go to the documentation of this file.
1
/*
2
* loop.c
3
*
4
* Iteration functions. This has *a lot* of similarity to try/catch --
5
* essentially what `recur` does is throw a special purpose exception which is
6
* caught by `loop`.
7
*
8
* Essentially the syntax I want is
9
*
10
* (defun expt (n e)
11
* (loop ((n1 . n) (r . n) (e1 . e))
12
* (cond ((= e 0) r)
13
* (t (recur n1 (* n1 r) (- e 1)))))
14
*
15
* It might in future be good to allow the body of the loop to comprise many
16
* expressions, like a `progn`, but for now if you want that you can just
17
* shove a `progn` in. Note that, given that what `recur` is essentially
18
* doing is throwing a special purpose exception, the `recur` expression
19
* doesn't actually have to be in the same function as the `loop` expression.
20
*
21
* (c) 2021 Simon Brooke <simon@journeyman.cc>
22
* Licensed under GPL version 2.0, or, at your option, any later version.
23
*/
24
25
#include "
consspaceobject.h
"
26
#include "
lispops.h
"
27
#include "
loop.h
"
28
29
/**
30
* Special form, not dissimilar to `let`. Essentially,
31
*
32
* 1. the first arg (`args`) is an assoc list;
33
* 2. the second arg (`body`) is an expression.
34
*
35
* Each of the vals in the assoc list is evaluated, and bound to its
36
* respective key in a new environment. The body is then evaled in that
37
* environment. If the result is an object of type LOOP, it should carry
38
* a list of values of the same arity as args. Each of the keys in args
39
* is then rebound in a new environment to the respective value from the
40
* LOOP object, and body is then re-evaled in that environment.
41
*
42
* If the result is not a LOOP object, it is simply returned.
43
*/
44
struct
cons_pointer
45
lisp_loop
( struct
stack_frame
*frame,
struct
cons_pointer
frame_pointer,
46
struct
cons_pointer
env ) {
47
struct
cons_pointer
keys =
c_keys
( frame->arg[0] );
48
struct
cons_pointer
body = frame->arg[1];
49
50
}
consspaceobject.h
cons_pointer
An indirect pointer to a cons cell.
Definition
consspaceobject.h:415
stack_frame
A stack frame.
Definition
consspaceobject.h:431
c_keys
struct cons_pointer c_keys(struct cons_pointer store)
Definition
lispops.c:840
lispops.h
lisp_loop
struct cons_pointer lisp_loop(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Special form, not dissimilar to let.
Definition
loop.c:45
loop.h
workspace
post-scarcity
src
ops
loop.c
Generated by
1.9.8