trueagi-io / hyperon-experimental

MeTTa programming language implementation
https://metta-lang.dev
MIT License
153 stars 50 forks source link

Fix (unify ($x a) (b $x) ok nok) case #518

Closed vsbogd closed 11 months ago

vsbogd commented 12 months ago

(let (quoted $a) (quoted $b) ...) replaces variables in $a by the unique variables thus making matching in error case possible. Case operation also has this property. Thus new function is required to check the case when variables cannot be matched to fix the issue.

@tanksha please check it fixes the case you have

vsbogd commented 12 months ago

I compared performance with version below and implementation using case is faster, so I included it in this PR.

    (: unify (-> Atom Atom Atom Atom %Undefined%))
    (= (unify $a $b $then $else)
      (if (are-not-unified (are-unified $a $b)) $else $then))
    (: are-unified (-> Atom Atom Bool))
    (= (are-unified $a $a) True)
    (: are-not-unified (-> Bool Bool))
    (= (are-not-unified True) False)
    (= (are-not-unified (are-unified $x $y)) True)