From 3e4ff5902fac83a8ca40bf05debe6816a6f6cf2b Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Sat, 24 Jul 2021 14:22:10 -0600 Subject: [PATCH] Completely change naming conventions of field forms and definition macros. Close #32 --- src/nat/Archive.kiss | 18 +++++++++--------- src/nat/ArchiveController.kiss | 10 +++++----- src/nat/BoolExpInterp.kiss | 4 ++-- src/nat/CLI.kiss | 22 +++++++++++----------- src/nat/Lib.kiss | 8 ++++---- src/nat/System.kiss | 6 +++--- src/test/TestMain.kiss | 4 ++-- 7 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/nat/Archive.kiss b/src/nat/Archive.kiss index 9a924bb..1c2d3ce 100644 --- a/src/nat/Archive.kiss +++ b/src/nat/Archive.kiss @@ -10,14 +10,14 @@ (let [entryFiles (FileSystem.readDirectory entryDir)] (for file entryFiles =>(file.withoutExtension) (the Entry (Json.parse (File.getContent (joinPath archiveDir "entries" file)))))))]) -(defmethod addSystem [:System system] +(method addSystem [:System system] // Assign entries to the Systems that care about them (doFor =>id entry entries (system.checkEntryInOrOut this entry)) (systems.push system) system) -(defmethod :Entry createEntry [:Entry->Dynamic initializer] // initializer returns Dynamic so ->:Void isn't required +(method :Entry createEntry [:Entry->Dynamic initializer] // initializer returns Dynamic so ->:Void isn't required (let [e (_newEntry)] (initializer e) (dictSet entries e.id e) @@ -26,20 +26,20 @@ // After modifying an entry, this must be called. If you are writing in a createEntry initializer or a system's processEntry function, this will happen automatically. // Otherwise, you can guarantee it happens automatically by using the (withWritableEntry) macro in Lib.kiss -(defmethod refreshEntry [:Entry e] +(method refreshEntry [:Entry e] (_saveEntry e) (doFor system systems (system.checkEntryInOrOut this e))) -(defmethod _saveEntry [:Entry e] +(method _saveEntry [:Entry e] (File.saveContent (joinPath archiveDir "entries" (e.id.withExtension "json")) (Json.stringify e))) -(defmethod componentData [:Entry e :String componentType] +(method componentData [:Entry e :String componentType] (haxe.Json.parse (File.getContent (joinPath archiveDir "components" "$(dictGet e.components componentType).json")))) -(defmethod fullData [:Entry e] +(method fullData [:Entry e] (object id e.id components @@ -48,11 +48,11 @@ files e.files)) -(defmethod fullString [:Entry e] +(method fullString [:Entry e] (haxe.Json.stringify (fullData e) null "\t")) -(defun :Entry _newEntry [] +(function :Entry _newEntry [] (object id (Uuid.v4) components (new Map) - files [])) \ No newline at end of file + files [])) diff --git a/src/nat/ArchiveController.kiss b/src/nat/ArchiveController.kiss index 628b266..6b4de40 100644 --- a/src/nat/ArchiveController.kiss +++ b/src/nat/ArchiveController.kiss @@ -1,6 +1,6 @@ (load "Lib.kiss") -(defmethod :Void _collectAndValidateArg [:CommandArg arg :Dynamic->Void continuation] +(method :Void _collectAndValidateArg [:CommandArg arg :Dynamic->Void continuation] (case arg.type (SelectedEntry (if (= 1 selectedEntries.length) @@ -91,11 +91,11 @@ min max)))) -(defmethod :Void->Void _composeArgCollector [:Array collectedArgs :CommandArg arg :Void->Void lastCollector] +(method :Void->Void _composeArgCollector [:Array collectedArgs :CommandArg arg :Void->Void lastCollector] (lambda :Void [] (_collectAndValidateArg arg ->:Void [:Dynamic argValue] {(collectedArgs.push argValue) (lastCollector)}))) -(defmethod :Void runCommand [:Command command] +(method :Void runCommand [:Command command] (let [collectedArgs [] &mut lastCollector @@ -125,7 +125,7 @@ (for [name type] argPairs `(object name ,(symbolName name) type ,type))] `{ - (defmethod ,name [,@methodArgs] ,@body) + (method ,name [,@methodArgs] ,@body) (dictSet commands ,(symbolName name) (object args [,@commandArgs] handler (the Function ,name)))})) (defnew [&prop :Archive archive @@ -184,4 +184,4 @@ (selectEntries (filter archive.entries ->e (tagsMatch archive e tagsBoolExp)))) (defcommand selectByComponents [componentsBoolExp (Text null)] - (selectEntries (filter archive.entries ->e (componentsMatch e componentsBoolExp))))) \ No newline at end of file + (selectEntries (filter archive.entries ->e (componentsMatch e componentsBoolExp))))) diff --git a/src/nat/BoolExpInterp.kiss b/src/nat/BoolExpInterp.kiss index df53363..e11f3cd 100644 --- a/src/nat/BoolExpInterp.kiss +++ b/src/nat/BoolExpInterp.kiss @@ -1,4 +1,4 @@ -(defun eval [:String expStr :Array activeConditions] +(function eval [:String expStr :Array activeConditions] (let [hscriptExp (.parseString (new Parser) (Prelude.convertToHScript expStr)) @@ -6,4 +6,4 @@ (new BoolExpInterp)] (doFor condition activeConditions (interp.variables.set condition true)) - ?(interp.execute hscriptExp))) \ No newline at end of file + ?(interp.execute hscriptExp))) diff --git a/src/nat/CLI.kiss b/src/nat/CLI.kiss index 28bc623..6562098 100644 --- a/src/nat/CLI.kiss +++ b/src/nat/CLI.kiss @@ -1,6 +1,6 @@ (load "Lib.kiss") -(defun :Void main [] +(function :Void main [] (let [[archiveDir] (Sys.args) controller (new ArchiveController @@ -16,7 +16,7 @@ (defnew []) -(defmethod :Void enterText [prompt resolve maxLength] +(method :Void enterText [prompt resolve maxLength] (Sys.print "$prompt ") (loop (let [entered (.toString (.readLine (Sys.stdin)))] @@ -25,7 +25,7 @@ {(resolve entered) (break)})))) -(defmethod :Void enterNumber [prompt resolve min max &opt inStepsOf] +(method :Void enterNumber [prompt resolve min max &opt inStepsOf] (Sys.print "$prompt ") (loop (let [entered (Std.parseFloat (.toString (.readLine (Sys.stdin))))] @@ -37,10 +37,10 @@ {(resolve entered) (break)})))) -(defmethod :Void chooseEntry [prompt :Archive archive resolve] +(method :Void chooseEntry [prompt :Archive archive resolve] (_chooseEntry prompt archive resolve ->(chooseEntry "empty name doesn't match any entries. Try again?" archive resolve))) -(defmethod :Void _chooseEntry [prompt :Archive archive resolve onEmptyString] +(method :Void _chooseEntry [prompt :Archive archive resolve onEmptyString] // TODO allow narrowing down with a tag string (enterText "entry name for $prompt" ->name { @@ -59,10 +59,10 @@ (multipleEntries (throw "ambiguous between multiple entries")))))} Math.POSITIVE_INFINITY)) -(defmethod :Void chooseEntries [prompt archive resolve min max] +(method :Void chooseEntries [prompt archive resolve min max] (_chooseEntries prompt archive resolve min max [])) -(defmethod :Void _chooseEntries [prompt archive resolve min max :Array collectedEntries] +(method :Void _chooseEntries [prompt archive resolve min max :Array collectedEntries] (let [onEmptyString ->(if (<= min collectedEntries.length) (resolve collectedEntries) @@ -84,12 +84,12 @@ (_chooseNextEntry))) -(defmethod handleChanges [:Archive archive :ChangeSet changeSet] +(method handleChanges [:Archive archive :ChangeSet changeSet] (doFor e changeSet (print (archive.fullString e)))) -(defmethod :Void displayMessage [message] +(method :Void displayMessage [message] (print message)) -(defmethod :Void reportError [error] - (print error)) \ No newline at end of file +(method :Void reportError [error] + (print error)) diff --git a/src/nat/Lib.kiss b/src/nat/Lib.kiss index 843de18..2510b87 100644 --- a/src/nat/Lib.kiss +++ b/src/nat/Lib.kiss @@ -64,13 +64,13 @@ (= ,value (readComponent ,archive e ,componentType)))) ,process)) -(defun tagList [archive e] +(function tagList [archive e] (let [t (readComponent archive e Tags)] (collect (t.keys)))) -(defun tagsMatch [archive e tagsBoolExp] +(function tagsMatch [archive e tagsBoolExp] (BoolExpInterp.eval tagsBoolExp (tagList archive e))) -(defun componentsMatch [:nat.Entry e componentsBoolExp] - (BoolExpInterp.eval componentsBoolExp (for =>cType cId e.components cType))) \ No newline at end of file +(function componentsMatch [:nat.Entry e componentsBoolExp] + (BoolExpInterp.eval componentsBoolExp (for =>cType cId e.components cType))) diff --git a/src/nat/System.kiss b/src/nat/System.kiss index 1debcd2..44c84d9 100644 --- a/src/nat/System.kiss +++ b/src/nat/System.kiss @@ -1,6 +1,6 @@ -(defprop :Map entries (new Map)) +(prop :Map entries (new Map)) -(defmethod :Void process [:Archive archive] +(method :Void process [:Archive archive] (doFor e (entries.iterator) (processEntry archive e) (archive.refreshEntry e))) @@ -9,7 +9,7 @@ &prop :EntryProcessor processEntry] []) -(defmethod :Void checkEntryInOrOut [:Archive archive :Entry e] +(method :Void checkEntryInOrOut [:Archive archive :Entry e] (if (canProcessEntry archive e) (dictSet entries e.id e) (entries.remove e.id))) diff --git a/src/test/TestMain.kiss b/src/test/TestMain.kiss index c9c919e..40334c4 100644 --- a/src/test/TestMain.kiss +++ b/src/test/TestMain.kiss @@ -4,7 +4,7 @@ (load "../nat/Lib.kiss") -(defun :Void main [] +(function :Void main [] (assert (BoolExpInterp.eval "true" [])) (assert !(BoolExpInterp.eval "false" [])) (assert !(BoolExpInterp.eval "flag" [])) @@ -32,4 +32,4 @@ [author Author name Name] (assert (= author "Rafael Krux")) - (assert (= name "Adventure"))))) \ No newline at end of file + (assert (= name "Adventure")))))