aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--2022/puzzle-7.lisp35
1 files changed, 35 insertions, 0 deletions
diff --git a/2022/puzzle-7.lisp b/2022/puzzle-7.lisp
index 3a4f353..a9b302c 100644
--- a/2022/puzzle-7.lisp
+++ b/2022/puzzle-7.lisp
@@ -21,6 +21,41 @@ tokens (including command)."
if (token-cmdp (car token-set))
return token-set))
+#| What is a directory structure? You have some root directory, with
+some entries. Your current working directory (CWD), at the start of
+the program, will be at the root but later on could be any descendant
+of the root. How do we manage moving around the directory structure
+and ensure updates to the root?
+
+We should maintain a HISTORY stack where
+CAR(HISTORY) = (NAME of CWD . State of CWD when entering).
+
+Firstly a function which updates the HISTORY on our current state.
+UPDATE-CURRENT-DIRECTORY(CWD, HISTORY) {
+CWD-ENTRY = PEEK(HISTORY);
+IF NULL(CWD-ENTRY)
+HISTORY = ((NIL . CWD))
+ELSE
+SETF((CDR CWD-ENTRY), CWD);
+}
+
+Say CWD = {... a = directory, b = file, ...}
+DOWN-DIRECTORY(a, CWD, HISTORY) {
+UPDATE-CURRENT-DIRECTORY(CWD, HISTORY); <-- This is so we don't lose information
+HISTORY = ACONS(a, CWD@a, HISTORY);
+CWD = CWD@a;
+}
+
+
+Then UP-DIRECTORY(CWD, HISTORY) {
+PAIR = POP(HISTORY); <-- (CWD-NAME . PREVIOUS-CWD-STATE)
+PARENT = PEEK(HISTORY); <-- Parent of CWD (PARENT-NAME . PARENT-STATE)
+ENTRY = ASSOC(CAR(PAIR) CDR(PARENT)) <-- Gives us the CWD entry in the parent
+SETF CDR(ENTRY) CWD <-- Update the parent
+CWD = CDR(PARENT) <-- Update CWD
+}
+|#
+
(defun parse-ls (tokens)
"Converts the following TOKENS till a command (via TOKEN-CMDP) into a
directory structure i.e. an alist of string names by their content."