Made a rough sketch comment of puzzle-7 structure

This commit is contained in:
2023-10-17 15:06:53 +01:00
parent 9c1e581524
commit 31878dd6e8

View File

@@ -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."