-
Notifications
You must be signed in to change notification settings - Fork 13
AssertEqual, AssertEqualToResults Disentanglement
These two statements, assertEqual and assertEqualToResult, appear superficially simple. In both, the first expression is evaluated and the result compared to the second expression. In both cases True is returned if equal, otherwise False. Importantly, crucial nuances exist as described below.
;; Public MeTTa
(@doc assertEqual
(@desc "Compares (sets of) results of evaluation of two expressions")
(@params (
(@param "First expression")
(@param "Second expression")))
(@return "Unit atom if both expression after evaluation is equal, error - otherwise"))
(: assertEqual (-> Atom Atom Atom))
;; Implemented from Interpreters
;; Public MeTTa
(@doc assertEqualToResult
(@desc "Same as assertEqual but it doesn't evaluate second argument. Second argument is considered as a set of values of the first argument's evaluation")
(@params (
(@param "First expression (it will be evaluated)")
(@param "Second expression (it won't be evaluated)")))
(@return "Unit atom if both expression after evaluation is equal, error - otherwise"))
(: assertEqualToResult (-> Atom Atom Atom))
;; Implemented from Interpreters
A value of True is returned as '[()]' and False is an error accompanied by the discrepancies.
In the assertEqual, both expressions are evaluated. In assertEqualToResult, the second expression is not evaluated.
assertEqualToResult uses == which is a hard equal while assertEqual uses =@= which is the alpha equivalent.
The alpha equivalent =@= means "if you rename the variables to their subjective meaning the structures would be the same." The == must pass pointer equality.
(= (loves $x $y) (likes $x $y))
(= (loves $a $b) (likes $a $b))
The above two expressions are =@= alpha equivalent applicable to assertEqual.
(= (loves $x $y) (likes $x $y))
(= (loves $x $y) (likes $x $y))
The above two expressions are == variable pointer equivalence applicable to assertEqualToResult.
Backtracking is relevant when making the comparisons of equality. With assertEqual both arguments are subject to backtracking and it is a softer comparison. However assertEqualToResult "freezes" the backtracking on the second argument. This means that to decide equality the system will backtrack through the entire first argument evaluation and compare a resulting list to the second argument taken literally (no backtracking).