select.km 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. type ABC enum {
  2. type A;
  3. type B;
  4. type C;
  5. };
  6. const A: ABC := { |ABC| { |A| () } };
  7. const B: ABC := { |ABC| { |B| () } };
  8. const C: ABC := { |ABC| { |C| () } };
  9. function parse-abc:
  10. &(String) => ABC
  11. &(str) =>
  12. if (str = 'A'):
  13. A,
  14. elif (str = 'B'):
  15. B,
  16. elif (str = 'C'):
  17. C,
  18. else:
  19. { panic 'invalid ABC' };
  20. function String:
  21. &(ABC) => String
  22. &(x) =>
  23. switch x:
  24. case A: 'A',
  25. case B: 'B',
  26. case C: 'C',
  27. end;
  28. function f:
  29. &(ABC,ABC) => ABC
  30. &(x,y) =>
  31. select (x,y):
  32. case (A,A): A,
  33. case (A,B): C,
  34. case (A,C): B,
  35. case (B,A),(B,B),(B,C): B,
  36. case (C,A): B,
  37. case (C,B): A,
  38. case (C,C): C,
  39. end;
  40. do { os::scanln () }
  41. . { then &(x-str) =>
  42. { os::scanln () }
  43. . { then &(y-str) =>
  44. let z := { f ({parse-abc(x-str)}, {parse-abc(y-str)}) },
  45. { os::println z.{String} }
  46. }
  47. }
  48. . { crash-on-error };