diff options
author | Nathan Ringo <nathan@remexre.com> | 2024-01-24 19:13:45 -0600 |
---|---|---|
committer | Nathan Ringo <nathan@remexre.com> | 2024-01-24 19:13:45 -0600 |
commit | a4c90a9c3ed05ead786e5e3fc06ad7e6bbd77b57 (patch) | |
tree | 8e724c3b56e95208f59564c73911c183f221b1f4 /discocaml/discocaml.ml | |
parent | 00d3ea6b17b73594c95318adf266802b02f65abb (diff) |
However... this is now no longer doing capture-avoiding substitution for
letrecs... and making the variable the redex kinda makes it harder to do
the substitution...
Maybe it's time to switch to using pointers in variables.
Diffstat (limited to 'discocaml/discocaml.ml')
-rw-r--r-- | discocaml/discocaml.ml | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/discocaml/discocaml.ml b/discocaml/discocaml.ml index ba407c1..a3f34f7 100644 --- a/discocaml/discocaml.ml +++ b/discocaml/discocaml.ml @@ -44,28 +44,31 @@ let handle_request { expr; command } : response = let buf = Lexing.from_string expr in let expr = Parse.expression buf in let expr = expr_of_parsetree expr in + let binders = get_binders expr in let expr_response ?(note : string option) (expr : expr ast) : response = `Expr { expr = show_expr expr; - has_redex = Option.is_some (Eval.find_redex_cbn expr); + has_redex = Option.is_some (Eval.find_redex_cbn expr binders); note; } in - let step_with (find_redex : expr ast -> expr index option) (expr : expr ast) - : expr ast = - match find_redex expr with - | Some i -> Eval.reduce expr i + let step_with + (find_redex : expr ast -> binder_info option array -> expr index option) + (expr : expr ast) : expr ast = + match find_redex expr binders with + | Some i -> Eval.reduce expr binders i | None -> failwith "no redex" in - let run_with (find_redex : expr ast -> expr index option) : - expr ast -> expr ast Seq.t = + let run_with + (find_redex : expr ast -> binder_info option array -> expr index option) + : expr ast -> expr ast Seq.t = let rec loop (expr : expr ast) : expr ast Seq.t = Seq.cons expr (fun () -> - match find_redex expr with - | Some i -> loop (Eval.reduce expr i) () + match find_redex expr binders with + | Some i -> loop (Eval.reduce expr binders i) () | None -> Nil) in loop |