creating:jlists

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
creating:jlists [2025/04/28 20:27] – Implemented jlist flattening ahelwercreating:jlists [2025/05/21 18:21] (current) – Disjunction does not short-circuit ahelwer
Line 253: Line 253:
  
 Now that we can parse jlists, let's interpret them. Now that we can parse jlists, let's interpret them.
-Similar to the logical operators covered in the book, jlists short-circuit. +Similar to the logical operators covered in the book, conjunction lists short-circuit. 
-This means juncts are evaluated in order and, if a conjunct is false or a disjunct is true, evaluation stops and immediately returns false or true respectively.+That means conjuncts are evaluated in order and, if a single conjunct is false, evaluation immediately stops and returns false
 +In an odd contrast, disjunction lists do //not// short-circuit; this is because they are used to express nondeterminism, as you will learn several chapters from now.
  
 Add conjunction list evaluation logic to ''visitVariadicExpr()'' in the ''Interpreter'' class, below the set constructor logic: Add conjunction list evaluation logic to ''visitVariadicExpr()'' in the ''Interpreter'' class, below the set constructor logic:
Line 272: Line 273:
  
 Then add the disjunction list logic right below that: Then add the disjunction list logic right below that:
-<code java [highlight_lines_extra="2,3,4,5,6,7,8"]>+<code java [highlight_lines_extra="2,3,4,5,6,7,8,9"]>
         return true;         return true;
       case OR:       case OR:
 +        boolean result = false;
         for (Expr disjunct : expr.parameters) {         for (Expr disjunct : expr.parameters) {
-          Object result = evaluate(disjunct); +          Object junctResult = evaluate(disjunct); 
-          checkBooleanOperand(expr.operator, result); +          checkBooleanOperand(expr.operator, junctResult); 
-          if ((boolean)resultreturn true;+          result |= (Boolean)junctResult;
         }         }
-        return false;+        return result;
       default:       default:
         // Unreachable.         // Unreachable.
  • creating/jlists.txt
  • Last modified: 2025/05/21 18:21
  • by ahelwer