-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathglobal-state.lisp
42 lines (35 loc) · 1.31 KB
/
global-state.lisp
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
(defpackage :overlord/global-state
(:use :cl :serapeum)
(:export
#:define-global-state
#:reset-global-state))
(in-package :overlord/global-state)
(defvar *initial-pathname-defaults*
*default-pathname-defaults*)
(defvar *initial-working-dir*
(uiop:getcwd))
(defvar *global-state*
(list
(cons '*default-pathname-defaults* (lambda () *initial-pathname-defaults*))
(cons '*readtable* (lambda () (copy-readtable nil)))
(cons '*read-base* (constantly 10))
(cons '*read-default-float-format* (constantly 'double-float))))
(defmacro define-global-state (name init &body (&optional docstring))
`(progn
(pushnew (cons ',name
(lambda ()
,init))
*global-state*
:key #'car)
(defvar ,name ,init
,@(unsplice docstring))))
(defun reset-global-state ()
"Restore Overlord's global state to its value when first loaded.
This is intended to be the practical equivalent of quitting Lisp and
reloading: it completely resets Overlord's internal state.
Note that this does not reset *just* Overlord's state. It also resets
a number of Lisp global variables to their default values."
(uiop:chdir *initial-working-dir*)
(loop for (var . init) in *global-state*
collect var
do (setf (symbol-value var) (funcall init))))