Forked from patham9/gist:ee21bf485a2565ebcd0450ccccc557c8
Last active
August 3, 2023 13:44
-
-
Save TeamSPoon/62b26d489e653fee87ee74aa983d043b to your computer and use it in GitHub Desktop.
Prolog-like append/3 for Hyperon in MeTTa
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
use hyperon::metta::*; | |
use hyperon::metta::interpreter::*; | |
fn main() { | |
let space = metta_space(" | |
(= (append () $L $L) True) | |
(= (append (Cons $H $T) $L (Cons $H $R)) (append $T $L $R)) | |
"); | |
println!("{:?}", interpret(&space, &metta_atom("(append (Cons $A (Cons 2 $L1)) $L2 (Cons 1 (Cons $B (Cons 2 (Cons 3 (Cons 4 ()))))))"))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
!(if (append (Cons $A (Cons 2 $L1)) $L2 (Cons 1 (Cons $B (Cons 3 (Cons 4 (Cons 5 ())))))) (print $A $B $L1 $L2) nop)
[(print 1 2 (Cons 3 (Cons 4 (Cons 5 ()))) ()),
(print 1 2 (Cons 3 (Cons 4 ())) (Cons 5 ())),
(print 1 2 (Cons 3 ()) (Cons 4 (Cons 5 ()))),
(print 1 2 () (Cons 3 (Cons 4 (Cons 5 ()))))]