mikaelpatel / Arduino-Shell

RPN Postscript/Forth Command Shell for Arduino
19 stars 5 forks source link

Question: Case statement #18

Closed dpharris closed 8 years ago

dpharris commented 8 years ago

This would be useful. Possible do it now, but messy: 2@ d0={(1st)}i d1={(2nd)i 2d={(3rd)}i

Alternately could use stack marker and 'C' perhaps:

[{(1st)}{(2nd)}{(3rd)}{(4th)}]2@C

C would need to check selector range, execute the appropriate block, and delete the block addresses from the stack.

May be guilding the lily.

mikaelpatel commented 8 years ago

Avoided this as it indirectly requires handling of multi-line (or larger command line buffer). The best solution for dispatch is to use several variables and index on their address.

dpharris commented 8 years ago

Great idea! So: if my state is in var 6, then: {...}\a0! {...}\a1! {...}\a2! {...}\a3! 6@@x

mikaelpatel commented 8 years ago

Yes! This is a great way to implement state-machines (see Cosa/FSM). I will close this issue for now. Might get back to it later.