small things

This commit is contained in:
gnembon committed 2025-02-19 11:13:31 +01:00
1 parent 6dd7bda6e4
commit 234c176670
3 files changed
+5 -4

No files matched your search

+2 -2
View File
@@ -1346,14 +1346,13 @@ public class Expression
{ {
String operator = pair.getKey(); String operator = pair.getKey();
String function = pair.getValue(); String function = pair.getValue();
if ((symbol.equals(operator) || symbol.equals(function)) && node.args.size() > 0) if ((symbol.equals(operator) || symbol.equals(function)) && !node.args.isEmpty())
{ {
boolean leftOptimizable = operators.get(operator).isLeftAssoc(); boolean leftOptimizable = operators.get(operator).isLeftAssoc();
ExpressionNode optimizedChild = node.args.get(leftOptimizable ? 0 : (node.args.size() - 1)); ExpressionNode optimizedChild = node.args.get(leftOptimizable ? 0 : (node.args.size() - 1));
String type = optimizedChild.token.surface; String type = optimizedChild.token.surface;
if ((type.equals(operator) || type.equals(function)) && (!(optimizedChild.op instanceof LazyValue.ContextFreeLazyValue))) if ((type.equals(operator) || type.equals(function)) && (!(optimizedChild.op instanceof LazyValue.ContextFreeLazyValue)))
{ {
optimized = true;
List<ExpressionNode> newargs = new ArrayList<>(); List<ExpressionNode> newargs = new ArrayList<>();
if (leftOptimizable) if (leftOptimizable)
{ {
@@ -1378,6 +1377,7 @@ public class Expression
} }
node.token.morph(Token.TokenType.FUNCTION, function); node.token.morph(Token.TokenType.FUNCTION, function);
node.args = newargs; node.args = newargs;
return true;
} }
} }
} }
@@ -346,6 +346,7 @@ public class Operators
return Value.TRUE; return Value.TRUE;
}); });
expression.addFunctionalEquivalence("==", "equal"); expression.addFunctionalEquivalence("==", "equal");
expression.addBinaryOperator("!=", precedence.get("equal==!="), false, (v1, v2) -> expression.addBinaryOperator("!=", precedence.get("equal==!="), false, (v1, v2) ->
v1.equals(v2) ? Value.FALSE : Value.TRUE); v1.equals(v2) ? Value.FALSE : Value.TRUE);
expression.addFunction("unique", lv -> { expression.addFunction("unique", lv -> {
@@ -56,7 +56,7 @@ public abstract class LazyListValue extends AbstractListValue implements Iterato
@Override @Override
public String getString() public String getString()
{ {
return String.format(Locale.ROOT, "[%s, %s, ..., %s)", NumericValue.of(start).getString(), NumericValue.of(start + stepp).getString(), NumericValue.of(limit).getString()); return String.format(Locale.ROOT, "<%s, %s, ..., %s)", NumericValue.of(start).getString(), NumericValue.of(start + stepp).getString(), NumericValue.of(limit).getString());
} }
}; };
} }
@@ -104,7 +104,7 @@ public abstract class LazyListValue extends AbstractListValue implements Iterato
@Override @Override
public String getString() public String getString()
{ {
return String.format(Locale.ROOT, "[%s, %s, ..., %s)", NumericValue.of(start).getString(), NumericValue.of(start + stepp).getString(), NumericValue.of(limit).getString()); return String.format(Locale.ROOT, "<%s, %s, ..., %s)", NumericValue.of(start).getString(), NumericValue.of(start + stepp).getString(), NumericValue.of(limit).getString());
} }
}; };
} }