// Checks if one of the operands is reducible public boolean isOperandsReducible() { for (Expression o : operands) { if (o.reducible()) { return true; } else if (!IsValue.isValue(o)) { return false; } } return false; }
public Vector<Expression> reduceOperandsByOneStep() { Vector<Expression> new_operands = operands; for (int i = 0; i < new_operands.size(); i++) { if (new_operands.get(i).reducible()) { new_operands.set(i, new_operands.get(i).oneStep()); } else if (!IsValue.isValue(new_operands.get(i))) { return new_operands; } } return new_operands; }
// Q: When is Function Application reducible? // A: When either its operands or operator is reducible public boolean reducible() { return operator.reducible() || (IsValue.isValue(operator) && isOperandsReducible()) || (IsValue.isValue(operator) && allOperandsAreValues()); }
public boolean allOperandsAreValues() { for (Expression o : operands) { if (!IsValue.isValue(o)) return false; } return true; }