tactiontable.nim 548 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. discard """
  2. output: '''
  3. action 3 arg
  4. action 3 arg
  5. '''
  6. """
  7. import tables
  8. proc action1(arg: string) =
  9. echo "action 1 ", arg
  10. proc action2(arg: string) =
  11. echo "action 2 ", arg
  12. proc action3(arg: string) =
  13. echo "action 3 ", arg
  14. proc action4(arg: string) =
  15. echo "action 4 ", arg
  16. var
  17. actionTable1 = {
  18. "A": action1,
  19. "B": action2,
  20. "C": action3,
  21. "D": action4}.toTable
  22. const
  23. actionTable2 = {
  24. "A": action1,
  25. "B": action2,
  26. "C": action3,
  27. "D": action4}.toTable
  28. actionTable1["C"]("arg")
  29. actionTable2["C"]("arg")