MyApp.k 631 B

123456789101112131415161718192021
  1. // We'll only use tST - tST itself will use other tables
  2. \l tST.k
  3. balance: 0; // amount of money inserted
  4. selection: 0; // selection - 0 is no selection
  5. dispensed: 0; // 1 if machine has dispensed successfully
  6. cancelBtn: 0; // 1 if user pressed cancel button
  7. // 1. money inserted
  8. balance+: 3;
  9. // tST -> start selecting, na: next action
  10. na: tST[(balance;selection;dispensed;cancelBtn);0N]; // 0N no args // This will update the state
  11. na[];
  12. // 2. select item
  13. selection: 1;
  14. na: tST[(balance;selection;dispensed;cancelBtn);0N];
  15. na[];
  16. // Here the machine must have dispensed, the stocks SS updated and machine is back to Idle again