Skip to content

Commit

Permalink
Merge pull request #193 from AdrickTench/main
Browse files Browse the repository at this point in the history
more tests/docs - load functions, save-space!, rust, rust!
  • Loading branch information
TeamSPoon authored Nov 19, 2024
2 parents f221a87 + bd65b07 commit f33fd7a
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 5 deletions.
53 changes: 48 additions & 5 deletions src/canary/stdlib_mettalog.metta
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
Expand All @@ -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"))
Expand All @@ -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")))
Expand Down Expand Up @@ -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")))
Expand All @@ -1836,9 +1836,52 @@

;; 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))

;; 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 !<atom>), 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! <atom>) and (rust !<atom>) are identical.")
(@params (
(@param "Atom to be evaluated")))
(@return "Result of evaluation"))
(: rust! (-> Atom Atom))
Original file line number Diff line number Diff line change
Expand Up @@ -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))

0 comments on commit f33fd7a

Please sign in to comment.