News for hackers. Stuff that matters.
Re:Ask HN: Can a state machine be stateless? by simonblack on Sunday June 12, 2022 @08:57PM (#31719805)
A state-machine could be considered as 'stateless' by being in a previously-undefined state. But that just means that 'this state' is an invalid state.

Example: Valid states have values of 1, 2 and 5. For some reason the current state has a value of 17. It's not a valid state but it is a state.

As such, there needs to be provision for it, generating an error of some kind. As in:

    ....
    
    switch (state){
    
      case ALPHA:
            printf("State is alpha\n");
            break;
    
      case BETA:
            printf("State is beta\n");
            break;
    
      case OMEGA:
            printf("State is omega\n");
            break;
    
      default:
            printf("ERROR!  State value %d is INVALID\n", state);
            error(state);
            break;
    }
    
    ....

There are no comments on this comment yet.