aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcos Magueta <maguetamarcos@gmail.com>2026-09-18 00:01:08 -0300
committerMarcos Magueta <maguetamarcos@gmail.com>2026-09-18 00:01:08 -0300
commit1d4125dd8ccbe272a190c155a4215daf1f362f10 (patch)
tree60ae213fef5e6c8a552ab7d8601557ede6c9ce43
parent24bb5eab738e291ee170f4fd563f39e33f65f37d (diff)
downloadRNT-1d4125dd8ccbe272a190c155a4215daf1f362f10.tar.gz
RNT-1d4125dd8ccbe272a190c155a4215daf1f362f10.zip
fix lambda test and execute
-rw-r--r--lib/evaluators/Lambda.ml8
-rw-r--r--test/unit/evaluators/Lambda.ml18
2 files changed, 18 insertions, 8 deletions
diff --git a/lib/evaluators/Lambda.ml b/lib/evaluators/Lambda.ml
index 48ae6ec..a75fc10 100644
--- a/lib/evaluators/Lambda.ml
+++ b/lib/evaluators/Lambda.ml
@@ -77,16 +77,18 @@ let reduce (Program (term, dir)) =
end
| Abstract (binder, body) -> Ok (Closure (binder, body, env))
| Apply (operator, operand) ->
- let* operator = eval env operation in
+ let* operator = eval env operator in
match operator with
| Relation _ -> Error (Error.not_applicable ())
- | _ -> failwith "TODO"
+ | Closure (binder, body, closed) ->
+ let* argument = eval env operand in
+ eval (BatMap.String.add binder argument closed) body
in
eval BatMap.String.empty term
let execute term =
let open Utilities.Result in
- let* value = reduce context term in
+ let* value = reduce term in
match value with
| Closure _ -> Error (Error.unapplied_abstraction ())
| Relation handle ->
diff --git a/test/unit/evaluators/Lambda.ml b/test/unit/evaluators/Lambda.ml
index c1098cf..bc2a45d 100644
--- a/test/unit/evaluators/Lambda.ml
+++ b/test/unit/evaluators/Lambda.ml
@@ -21,6 +21,10 @@ module Make (S : Abstract.Storage.STORAGE) (C : Helpers.Storage.CONFIGURATOR) =
BatMap.String.empty
|> BatMap.String.add "lemma" (Concepts.Value.String "rēticulāre") }
+ let not_a_directory () =
+ Concepts.Condition.condition "not-a-directory"
+ "A handle was expected to carry the directory protocol and did not" Concepts.Condition.empty
+
let not_a_program () =
Concepts.Condition.condition "not-a-program"
"A handle was expected to carry the program protocol and did not" Concepts.Condition.empty
@@ -46,14 +50,18 @@ module Make (S : Abstract.Storage.STORAGE) (C : Helpers.Storage.CONFIGURATOR) =
[ Kernel.Prototype.Directory.of_properties
["noun", noun; "verb", verb; "lambda", Rnt.Evaluators.Lambda.make ()] ]
in
- let context = Runtime.Context.over ~snapshot:(hash "snapshot") ~root () in
- let* found = Runtime.Context.resolve context "lambda" in
+ let* directory =
+ Protocols.Directory.from root |> Option.to_result ~none:(not_a_directory ())
+ in
+ let* found = Protocols.Directory.find directory "lambda" in
let* evaluator = Option.to_result ~none:(not_a_program ()) found in
let* interpreter =
Rnt.Evaluators.Lambda.Program.from evaluator
|> Option.to_result ~none:(not_a_program ())
in
- let* cursor = Rnt.Evaluators.Lambda.Program.invoke interpreter ~program:term context in
+ let* cursor =
+ Rnt.Evaluators.Lambda.(Program.invoke interpreter (Program (term, directory)))
+ in
let* scan = Protocols.Cursor.require cursor in
let* tuples = Protocols.Cursor.drain scan () in
Protocols.Handle.release cursor;
@@ -62,8 +70,8 @@ module Make (S : Abstract.Storage.STORAGE) (C : Helpers.Storage.CONFIGURATOR) =
let is lemma tuple =
Concepts.Hash.hash_equals (Concepts.Tuple.hash tuple) (Concepts.Tuple.hash lemma)
- (* A bare name resolves through the context, so the relations under
- the snapshot are the outer environment *)
+ (* A bare name resolves through the directory, so the relations it
+ holds are the outer environment *)
let a_name_is_a_relation conn =
let scanned =
evaluate conn (Rnt.Evaluators.Lambda.Name "noun") |> Helpers.condition_as_failure