summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2022-11-04 23:08:52 +0100
committerEkaitz Zarraga <ekaitz@elenq.tech>2022-11-04 23:08:52 +0100
commitaa969e72a34cc3d6e39495a4210442a5e9c7952c (patch)
tree01c004edfe846a2a16e12fbe04061b07a15870cf
parent30fdfca72ca1277c127c42e86bba2481246db0f7 (diff)
Recursive state rotation using macro magic
-rw-r--r--depre/main.scm35
1 files changed, 30 insertions, 5 deletions
diff --git a/depre/main.scm b/depre/main.scm
index 81bdb03..11b18fc 100644
--- a/depre/main.scm
+++ b/depre/main.scm
@@ -25,6 +25,18 @@
((car fs))
(loop (cdr fs))))))
+;; Transition by chance, according to the state
+;; Example:
+;; - You are too tired for that, so you do this instead
+;; - Or you actually do it
+(define (f-or-tired f tired)
+ #f
+ )
+
+(define (f-or-depressed f depressed)
+ #f
+ )
+
;; Simple I/O
(define (answer message)
(lambda ()
@@ -71,16 +83,29 @@
(loop (read)))))))
;; States:
-(define start
+
+;; Some macro magic for indirection that enables recursion.
+;; I don't really know how it works (yet!)
+(define %states (make-hash-table))
+(define-macro (register-state name f)
+ `(hash-set! %states ,name ,f))
+(define-macro (to-state name)
+ `(lambda () ((hash-ref %states ,name))))
+
+(register-state
+ 'begining
+ (state "This is the game beginning, as a test"
+ (list (cons "Return to start" (to-state 'start)))))
+
+(register-state
+ 'start
(state "Hi, game starts"
(list (cons "Start game"
(combine
(answer "Let's start, then.")
- (state "heading"
- (list (cons "hola" (lambda () (display "HOLA")))
- (cons "adios" (lambda () (display "adios")))))))
+ (to-state 'begining)))
(cons "Quit game"
(answer "Good bye!")))
#:hide-status))
-(start)
+((to-state 'start))