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
Next revision
Previous revision
creating:jlists [2025/05/21 18:21] – Disjunction does not short-circuit ahelwercreating:jlists [2025/11/04 17:32] (current) – Further simplified instanceof code ahelwer
Line 280: Line 280:
           Object junctResult = evaluate(disjunct);           Object junctResult = evaluate(disjunct);
           checkBooleanOperand(expr.operator, junctResult);           checkBooleanOperand(expr.operator, junctResult);
-          result |= (Boolean)junctResult;+          result |= (boolean)junctResult;
         }         }
         return result;         return result;
Line 355: Line 355:
     List<Expr> flattened = new ArrayList<>();     List<Expr> flattened = new ArrayList<>();
     for (Expr junct : juncts) {     for (Expr junct : juncts) {
-      Expr.Variadic vjunct; +      if (junct instanceof Expr.Variadic vjunct 
-      if ((vjunct = asVariadicOp(op, junct)) !null) {+          && vjunct.operator.type == op.type) {
         flattened.addAll(vjunct.parameters);         flattened.addAll(vjunct.parameters);
       } else {       } else {
Line 364: Line 364:
  
     return new Expr.Variadic(op, flattened);     return new Expr.Variadic(op, flattened);
-  } 
-</code> 
- 
-This uses Java's conditional-assign syntax along with the ''asVariadicOp()'' helper, which returns an ''Expr.Variadic'' instance if the given expression is a jlist of the given type: 
-<code java> 
-  private Expr.Variadic asVariadicOp(Token op, Expr expr) { 
-    if (expr instanceof Expr.Variadic) { 
-      Expr.Variadic vExpr = (Expr.Variadic)expr; 
-      if (vExpr.operator.type == op.type) return vExpr; 
-    } 
- 
-    return null; 
   }   }
 </code> </code>
  • creating/jlists.1747851711.txt.gz
  • Last modified: 2025/05/21 18:21
  • by ahelwer