From b27949df20493af57d23e572f0a9b6f4b99175d9 Mon Sep 17 00:00:00 2001 From: AdrickTench Date: Fri, 15 Nov 2024 11:34:20 -0600 Subject: [PATCH 1/3] update doc strings for load functions --- src/canary/stdlib_mettalog.metta | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/canary/stdlib_mettalog.metta b/src/canary/stdlib_mettalog.metta index 427c7beae8..2a42461126 100644 --- a/src/canary/stdlib_mettalog.metta +++ b/src/canary/stdlib_mettalog.metta @@ -1353,7 +1353,7 @@ ;; Public MeTTa (@doc import! - (@desc "Imports module using its relative path (second argument) and binds it to the token (first argument) which will represent imported atomspace. If first argument is &self then everything will be imported to current atomspace") + (@desc "Imports module using its relative path (second argument) and binds it to the token (first argument) which will represent imported atomspace. If first argument is &self then everything will be imported to current atomspace. The source is imported only the first time import! is called. Can load Python code (.py) or MeTTa (.metta); if ambiguous, assumes Python.") (@params ( (@param "Symbol, which is turned into the token for accessing the imported module") (@param "Module name"))) @@ -1363,7 +1363,7 @@ ;; Public MeTTa (@doc include - (@desc "Works just like import! but with &self as a first argument. So everything from input file will be included in the current atomspace and evaluated") + (@desc "Works just like include! but with &self as a first argument. So everything from input file will be included in the current atomspace and evaluated") (@params ( (@param "Name of metta script to import"))) (@return "Unit atom")) @@ -1372,7 +1372,7 @@ ;; Public MeTTa (@doc include! - (@desc "Works just like import!. So everything from input file will be included in the current atomspace and evaluated") + (@desc "Everything from input file will be included in the current atomspace and evaluated, as if it were being evaluated at the REPL. Unlike import!, the source is evaluated every time include! is called.") (@params ( (@param "Space") (@param "Filename"))) @@ -1827,7 +1827,7 @@ ;; Public MeTTaLog (@doc load-file! - (@desc "Loads the contents of Filename into Space, returning () if successful.") + (@desc "Loads the contents of Filename into Space, returning () if successful. Can load Python code (.py) or MeTTa (.metta); if ambiguous, assumes MeTTa. Like import! but favors MeTTa over Python when the file type is ambiguous.") (@params ( (@param "Space") (@param "Filename"))) From fa966c4873594627d0856525de4805e7ca3d28c6 Mon Sep 17 00:00:00 2001 From: AdrickTench Date: Fri, 15 Nov 2024 15:51:32 -0600 Subject: [PATCH 2/3] tests/docs for save-space! --- src/canary/stdlib_mettalog.metta | 19 ++++++++++++++++++- .../output_load_tests.metta | 17 +++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/canary/stdlib_mettalog.metta b/src/canary/stdlib_mettalog.metta index 2a42461126..0195dcc1df 100644 --- a/src/canary/stdlib_mettalog.metta +++ b/src/canary/stdlib_mettalog.metta @@ -1836,9 +1836,26 @@ ;; Public MeTTa (@doc load-ascii - (@desc "Loads the contents of Filename into Space, returning () if successful. Assumes the file is an ASCII file.") + (@desc "Loads the contents of Filename into Space, returning () if successful. Assumes the file is an ASCII file. Works like include!.") (@params ( (@param "Space") (@param "Filename"))) (@return "Expression")) (: load-ascii (-> hyperon::space::DynSpace String Expression)) + +;; Public MeTTa +(@doc transfer! + (@desc "Loads the contents of Filename into &self, as include. Returns () if successful, throws an exception otherwise.") + (@params ( + (@param "Filename"))) + (@return "Expression")) +(: transfer! (-> String Expression)) + +;; Public MeTTa +(@doc save-space! + (@desc "Writes the contents of Space into Filename, returning () if successful.") + (@params ( + (@param "Space") + (@param "Filename"))) + (@return "Expression")) +(: save-space! (-> hyperon::space::DynSpace String Expression)) diff --git a/tests/baseline_compat/hyperon-mettalog_sanity/output_load_tests.metta b/tests/baseline_compat/hyperon-mettalog_sanity/output_load_tests.metta index 9b4fbd9e42..7d625fcff2 100644 --- a/tests/baseline_compat/hyperon-mettalog_sanity/output_load_tests.metta +++ b/tests/baseline_compat/hyperon-mettalog_sanity/output_load_tests.metta @@ -60,3 +60,20 @@ ("(bar 1)" "(bar 2)")) !(assertEqualToResult (let $f (filename) (load-file! &self $f)) (())) !(assertEqualToResult (match &self (bar $x) $x) (1 2)) + +;; test save-space! + +!(bind! &gen-space (new-space)) +!(bind! &load-space (new-space)) + +!(add-atom &gen-space (likes John Jane)) +!(add-atom &gen-space (= (foo $x) (+ $x 1))) + +!(assertEqualToResult (match &gen-space (likes $x $y) ($x $y)) ((John Jane))) +!(assertEqualToResult (metta (foo 1) Number &new-space) (2)) + +!(assertEqualToResult (save-space! &gen-space "save-space-test.tmp") (())) +!(assertEqualToResult (load-file! &load-space "save-space-test.tmp") (())) + +!(assertEqualToResult (match &load-space (likes $x $y) ($x $y)) ((John Jane))) +!(assertEqualToResult (metta (foo 1) Number &load-space) (2)) From 70b7d47dc06435d2e9308d38c08b974add6a385a Mon Sep 17 00:00:00 2001 From: AdrickTench Date: Fri, 15 Nov 2024 16:56:59 -0600 Subject: [PATCH 3/3] docs for rust, rust! --- src/canary/stdlib_mettalog.metta | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/canary/stdlib_mettalog.metta b/src/canary/stdlib_mettalog.metta index 0195dcc1df..216559d333 100644 --- a/src/canary/stdlib_mettalog.metta +++ b/src/canary/stdlib_mettalog.metta @@ -1859,3 +1859,29 @@ (@param "Filename"))) (@return "Expression")) (: save-space! (-> hyperon::space::DynSpace String Expression)) + +;; MeTTaLog Debugging +(@doc rtrace! + (@desc "Fully evaluates input Atom, providing a complete trace of the evaluation.") + (@params ( + (@param "Atom to be evaluated"))) + (@return "Result of evaluation")) +(: rtrace! (-> Atom Atom)) + +;; Public MeTTaLog + +(@doc rust + (@desc "Interface with the rust / Hyperon MeTTa implementation. Enters Atom into rust atomspace. If Atom is evaluated (i.e. by being of the form !), returns the result of evaluation. See also rust!.") + (@params ( + (@param "Atom to be entered into the space"))) + (@return "Result of entering Atom into the space")) +(: rust (-> Atom Atom)) + +;; Public MeTTaLog + +(@doc rust! + (@desc "Like rust but evaluates the atom rather than entering into the space. (rust! ) and (rust !) are identical.") + (@params ( + (@param "Atom to be evaluated"))) + (@return "Result of evaluation")) +(: rust! (-> Atom Atom))