Error: not a statement

From Esolang
Jump to navigation Jump to search

Error: not a statement is a restricted subset of Java by User:Fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, which only allows expressions statements that would normally be flagged as not a statement.

The only statements that are allowed are var _ = expr; and return expr; and the following expressions are banned:

  • Increment/decrement operators
  • Assignments
  • Explicit method calls

So how do you do anything?

Well, the following operators can perform arbitrary functions without breaking the rules:

  • The + operator
  • The new operator


A basic program

public record Factorial(int first, int second) {  
  @Override
  public String toString() {
    return "" + first + second;
  }
}

Limitations

Unfortunately, there is no IO, as that requires a method call. If you want IO, create this class

public record IO(String out, IO.Mode mode) {
  @Override
  public String toString() {
    return switch(mode) {Mode.OUTPUT -> {System.out.println(out); yield out;}, Mode.INPUT -> new Scanner(System.in).nextLine()};
  }

  public static enum Mode {
    OUTPUT, INPUT;
  }
}