forked from trueagi-io/hyperon-experimental
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/trueagi-io/hyperon-experime…
- Loading branch information
Showing
28 changed files
with
516 additions
and
434 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,26 @@ | ||
use hyperon::metta::*; | ||
use hyperon::metta::interpreter::*; | ||
use hyperon::*; | ||
use hyperon::metta::runner::*; | ||
use hyperon::metta::runner::arithmetics::*; | ||
use hyperon::metta::text::SExprParser; | ||
|
||
fn main() { | ||
let space = metta_space(" | ||
fn main() -> Result<(), String> { | ||
let metta = Metta::new(None); | ||
metta.run(SExprParser::new(" | ||
(: List (-> $a Type)) | ||
(: Nil (List $a)) | ||
(: Cons (-> $a (List $a) (List $a))) | ||
(: if (-> bool Any Any) Any) | ||
(= (if true $then $else) $then) | ||
(= (if false $then $else) $else) | ||
(: insert (-> $a (List $a) (List $a))) | ||
(= (insert $x Nil) (Cons $x Nil)) | ||
(= (insert $x (Cons $head $tail)) (if (< $x $head) | ||
(Cons $x (Cons $head $tail)) | ||
(Cons $head (insert $x $tail)))) | ||
"); | ||
"))?; | ||
|
||
assert_eq!(metta.run(SExprParser::new("!(insert 1 Nil)"))?[0], | ||
vec![expr!("Cons" {Number::Integer(1)} "Nil")]); | ||
assert_eq!(metta.run(SExprParser::new("!(insert 3 (insert 2 (insert 1 Nil)))"))?[0], | ||
vec![expr!("Cons" {Number::Integer(1)} ("Cons" {Number::Integer(2)} ("Cons" {Number::Integer(3)} "Nil")))]); | ||
|
||
assert_eq!(interpret(&space, &metta_atom("(insert 1 Nil)")), | ||
Ok(vec![metta_atom("(Cons 1 Nil)")])); | ||
assert_eq!(interpret(&space, &metta_atom("(insert 3 (insert 2 (insert 1 Nil)))")), | ||
Ok(vec![metta_atom("(Cons 1 (Cons 2 (Cons 3 Nil)))")])); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
use crate::*; | ||
use crate::metta::text::{Tokenizer, SExprParser}; | ||
use crate::space::grounding::GroundingSpace; | ||
|
||
pub(crate) fn metta_space(text: &str) -> GroundingSpace { | ||
let mut space = GroundingSpace::new(); | ||
let mut parser = SExprParser::new(text); | ||
while let Some(atom) = parser.parse(&Tokenizer::new()).unwrap() { | ||
space.add(atom); | ||
} | ||
space | ||
} | ||
|
||
pub(crate) fn metta_atom(atom_str: &str) -> Atom { | ||
let mut parser = SExprParser::new(atom_str); | ||
let atom = parser.parse(&Tokenizer::new()).unwrap().expect("Single atom is expected"); | ||
atom | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.