about summary refs log tree commit diff stats
path: root/fe/parade.fe
blob: d52b43a2eb170cf37ff61a5aec4f77fadf51bd6b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
; A simple game engine, based on https://wiki.xxiivv.com/site/parade.html
; Primitives: CREATE, PROGRAM, USE, LOOK
; DATA: the world is a stack.

(= push
    (mac (val lst)
        (list '= lst (list 'cons val lst))))

(= for
    (mac (item lst . body)
        (list 'do
            (list 'let 'for-iter lst)
            (list 'while 'for-iter
                (list 'let item '(car for-iter))
            '(= for-iter (cdr for-iter))
            (cons 'do body)))))

(= create
    (fn (new-obj)
        (push (cons new-obj nil) world)
        world))

(= put
    (fn (to-put pair)
    	(do
            (setcdr pair to-put)
        pair)))

(= program
    (fn (target utility)
        (for x world
            (if (is  (car x) target) (put utility x)
                (not (car x) target) nil))))

(= all-of-creation
    (fn (lst)
        (print ">  Behold, all of creation!")
        (for x lst
           (print "> " x))))

(= look
    (fn (target)
        (for x world
            (if (is  (car x) target) (print ">  looking at" (car x) "reveals" (cdr x)))
                (not (car x) target) nil)))



(let world ())
(create "banana")
(create "kiwi")
(create "apple")
(create "tango")
(program "apple" "bath")
(program "tango" "dance")
(program "kiwi" "shoe")
(program "banana" "peel")

(all-of-creation world)

(print "")

(look "apple")
(look "tango")
(look "kiwi")
(look "banana")