From 31878dd6e8ed95a7abee3a25f2ec850f2ec3df4b Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Tue, 17 Oct 2023 15:06:53 +0100 Subject: Made a rough sketch comment of puzzle-7 structure --- 2022/puzzle-7.lisp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to '2022') 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." -- cgit v1.2.3-13-gbd6f