Skip to content

Commit

Permalink
Merge pull request #687 from trueagi-io/voidrm
Browse files Browse the repository at this point in the history
%void% -> Empty
  • Loading branch information
Necr0x0Der authored May 7, 2024
2 parents 6ab2a8e + a9df602 commit be3beb7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/src/metta/runner/stdlib.metta
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
(: unify (-> Atom Atom Atom Atom %Undefined%))
(= (unify $a $a $then $else) $then)
(= (unify $a $b $then $else)
(case (unify-or-empty $a $b) ((%void% $else))) )
(case (unify-or-empty $a $b) ((Empty $else))) )
(: unify-or-empty (-> Atom Atom Atom))
(= (unify-or-empty $a $a) unified)
(= (unify-or-empty $a $b) (empty))
Expand Down
8 changes: 3 additions & 5 deletions lib/src/metta/runner/stdlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ use regex::Regex;
use super::arithmetics::*;
use super::string::*;

pub const VOID_SYMBOL : Atom = sym!("%void%");

fn unit_result() -> Result<Vec<Atom>, ExecError> {
Ok(vec![UNIT_ATOM()])
}
Expand Down Expand Up @@ -1187,7 +1185,7 @@ mod non_minimal_only_stdlib {
Ok(result) if result.is_empty() => {
cases.into_iter()
.find_map(|(pattern, template, _external_vars)| {
if pattern == VOID_SYMBOL {
if pattern == EMPTY_SYMBOL {
Some(template)
} else {
None
Expand Down Expand Up @@ -1864,10 +1862,10 @@ mod tests {
let case_op = CaseOp::new(space.clone());

assert_eq!(case_op.execute(&mut vec![expr!(("foo")),
expr!(((n "B") n) ("%void%" "D"))]),
expr!(((n "B") n) ("Empty" "D"))]),
Ok(vec![Atom::sym("A")]));
assert_eq!(case_op.execute(&mut vec![expr!({MatchOp{}} {space} ("B" "C") ("C" "B")),
expr!(((n "C") n) ("%void%" "D"))]),
expr!(((n "C") n) ("Empty" "D"))]),
Ok(vec![Atom::sym("D")]));
}

Expand Down
12 changes: 4 additions & 8 deletions lib/src/metta/runner/stdlib_minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ use std::convert::TryInto;
use super::arithmetics::*;
use super::string::*;

pub const VOID_SYMBOL : Atom = sym!("%void%");

fn unit_result() -> Result<Vec<Atom>, ExecError> {
Ok(vec![UNIT_ATOM()])
}
Expand Down Expand Up @@ -410,9 +408,7 @@ impl Grounded for CaseOp {
log::debug!("CaseOp::execute: atom results: {:?}", results);
let results = match results {
Ok(results) if results.is_empty() =>
// TODO: MINIMAL in minimal MeTTa we should use Empty in both
// places here and in (case ...) calls in code
vec![switch(VOID_SYMBOL)],
vec![switch(EMPTY_SYMBOL)],
Ok(results) =>
results.into_iter().map(|atom| switch(atom)).collect(),
Err(err) => vec![Atom::expr([ERROR_SYMBOL, atom.clone(), Atom::sym(err)])],
Expand Down Expand Up @@ -633,13 +629,13 @@ mod tests {

#[test]
fn metta_case_empty() {
let result = run_program("!(case Empty ( (ok ok) (%void% nok) ))");
let result = run_program("!(case Empty ( (ok ok) (Empty nok) ))");
assert_eq!(result, Ok(vec![vec![expr!("nok")]]));
let result = run_program("!(case (unify (C B) (C B) ok Empty) ( (ok ok) (%void% nok) ))");
let result = run_program("!(case (unify (C B) (C B) ok Empty) ( (ok ok) (Empty nok) ))");
assert_eq!(result, Ok(vec![vec![expr!("ok")]]));
let result = run_program("!(case (unify (B C) (C B) ok nok) ( (ok ok) (nok nok) ))");
assert_eq!(result, Ok(vec![vec![expr!("nok")]]));
let result = run_program("!(case (unify (B C) (C B) ok Empty) ( (ok ok) (%void% nok) ))");
let result = run_program("!(case (unify (B C) (C B) ok Empty) ( (ok ok) (Empty nok) ))");
assert_eq!(result, Ok(vec![vec![expr!("nok")]]));
}

Expand Down
4 changes: 2 additions & 2 deletions lib/tests/case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ fn test_case_operation() {
(((Rel-P $y) (P $y))
((Rel-Q $y) (Q $y))))
; %void% can be used to capture empty results
; Empty can be used to capture empty results
!(case (match &self ($rel B $x) ($rel $x))
(((Rel-P $y) (P $y))
((Rel-Q $y) (Q $y))
(%void% no-match)))
(Empty no-match)))
; a functional example
(= (maybe-inc $x)
Expand Down

0 comments on commit be3beb7

Please sign in to comment.