creating:operators

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
creating:operators [2025/06/13 21:25] – Removed PrintStream parameter from Interpreter constructor ahelwercreating:operators [2025/06/19 14:50] (current) – ALL_MAP_TO interpretation splits out Object value = ahelwer
Line 297: Line 297:
 <code java [highlight_lines_extra="3"]> <code java [highlight_lines_extra="3"]>
     defineAst(outputDir, "Stmt", Arrays.asList(     defineAst(outputDir, "Stmt", Arrays.asList(
-      "Print    : Expr expression",+      "Print    : Token location, Expr expression",
       "OpDef    : Token name, List<Token> params, Expr body"       "OpDef    : Token name, List<Token> params, Expr body"
     ));     ));
Line 304: Line 304:
 We can now parse operators with parameters! We can now parse operators with parameters!
 On to functions. On to functions.
-This requires defining a new expression type in the ''GenerateAST'' class:+This requires defining a new expression type in the ''GenerateAst'' class:
 <code java [highlight_lines_extra="3"]> <code java [highlight_lines_extra="3"]>
     defineAst(outputDir, "Expr", Arrays.asList(     defineAst(outputDir, "Expr", Arrays.asList(
Line 569: Line 569:
 One important thing to note is that unlike in ''TlaOperator'', we give ''BindingGenerator'' the //current// environment instead of the root global environment; this is because if we are evaluating an ''Expr.QuantFn'' instance inside an operator, the body expression should be able to access definitions from the operator's environment, like: One important thing to note is that unlike in ''TlaOperator'', we give ''BindingGenerator'' the //current// environment instead of the root global environment; this is because if we are evaluating an ''Expr.QuantFn'' instance inside an operator, the body expression should be able to access definitions from the operator's environment, like:
 <code haskell> <code haskell>
-op(x) == \A y \in 0 .. 2 : y < x +op(x) == \A y \in 0 .. 2 : y < x
 </code> </code>
 Here's how we implement the ''EXISTS'' case; unlike universal quantification, existential quantification is not short-circuiting in TLA⁺ (for reasons that will become clear in the next chapter): Here's how we implement the ''EXISTS'' case; unlike universal quantification, existential quantification is not short-circuiting in TLA⁺ (for reasons that will become clear in the next chapter):
Line 584: Line 584:
 </code> </code>
 Finally, here's how we implement the ''ALL_MAP_TO'' case; we want to construct a ''Map<Object, Object>'' instance recording each value the single parameter is mapped to: Finally, here's how we implement the ''ALL_MAP_TO'' case; we want to construct a ''Map<Object, Object>'' instance recording each value the single parameter is mapped to:
-<code java [highlight_lines_extra="2,3,4,5,6,7"]>+<code java [highlight_lines_extra="2,3,4,5,6,7,8"]>
       case ALL_MAP_TO: {       case ALL_MAP_TO: {
         Token param = expr.params.get(0);         Token param = expr.params.get(0);
         Map<Object, Object> function = new HashMap<>();         Map<Object, Object> function = new HashMap<>();
         for (Environment binding : bindings) {         for (Environment binding : bindings) {
-          function.put(binding.get(param), executeBlock(expr.body, binding));+          Object value = executeBlock(expr.body, binding); 
 +          function.put(binding.get(param), value);
         }         }
         return function;         return function;
  • creating/operators.1749849923.txt.gz
  • Last modified: 2025/06/13 21:25
  • by ahelwer