README 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. RAKU is a scripting language that resembles Engish somewhat.
  2. However it is a stealth lisp with smalltalk like semantics.
  3. In Lisp you would say (function1 arg1 (function2 arg2))
  4. In C you would write function1(arg1, function2(arg2));
  5. In Raku you will write function1 arg1 be function2 arg2 so
  6. attack the greater green gorgon with the large axe
  7. # Core problem: in most languages, arguments of a function are not only
  8. # delimited, but also the start and end of the function call
  9. # are indicated somehow, so that calling several functions in one statement
  10. # is possible. Similarly for message passing.
  11. # C-like:
  12. # foo(a, b, c)
  13. # foo(a, bar(b , c) ,d ,e)
  14. # Lisp-like:
  15. # (foo a b c)
  16. # (foo a (bar b c) d e)
  17. # What I'd like for Raku is drop the outer ()
  18. # foo a (bar b c) d e
  19. # Here the newline at the end, or the . make is clear the statement is finished.
  20. # However, calling functions still requires a special delimiter.
  21. # Unless if the parser knows that foo and bar are functions/methods/verbs.
  22. # Then it can distinguish between foo and bar and a b c d e.
  23. # But then it still can't see where an inner call ends and the top level
  24. # one begins: VERB NOUN PREP VERB NOUN PREP NOUN EOL ->
  25. # is this VERB(NOUN , VERB(NOUN, NOUN)) or VERB(NOUN , VERB(NOUN), NOUN)?
  26. # Without an end-of call delimiter the parser cannot know.
  27. # For the simple case of VERB NOUN PERP NOUN EOL
  28. # the EOL acts as the "end of call" marker, but it can't be used twice.
  29. #
  30. # I checked Inform 7 but it's a huge language with many unnecessary
  31. # complexities. It's simpler to solve the delimiter problem by using short words.
  32. #
  33. # an as at ax be by do go if of in is it me no of or ox so to up us we
  34. #
  35. #
  36. # set foobar to be add 10 to 10 so
  37. # set foobar to tally add 10 to 10 end
  38. # for i from 0 to be size foo so then do
  39. #
  40. # end
  41. # do / sub / block ... so / end / done -> block
  42. # be / run / call ... so / end / done -> sub-call, parenthesis
  43. # list / array ... so / end / done -> array/list value
  44. # act / define WORD [NAME [PREP NAME] BLOCK-> method definition on first NAME, which should be a type or instance. If none is given, "me" is used.
  45. # use NAME -> variable declaration takes values of arguments give to block if any.
  46. # nil / nothing / none / -> nil value
  47. # true / false / yes / no -> boolean value
  48. # return -> method return
  49. # yield -> block return
  50. This is unambiguous in IO or Potion:
  51. OBJECT METHOD1(ARG1_1, ARG1_2, ...) METHOD2(ARG2_1, ...) METHOD3 EOL
  52. # Inversed, apart from the parameters this becomes:
  53. METHOD3 METHOD2(ARG_2_1, ...) METHOD1(ARG1_1, ARG1_2, ....) OBJECT
  54. #
  55. # So io/potion ish
  56. Bob name append(" and ", Jane name) println
  57. # Would invert to
  58. println append(" and ", name Jane ) name Bob
  59. # now substitute the non-words with words
  60. println append of " and " with name Jane end name Bob
  61. # or if we use and for method chaining
  62. println and append " and " with name Jane and name Bob
  63. # So io/potion ish
  64. Bob hp decrease(Bob hp times(10) divide(Bob hpmax))
  65. # Would invert to
  66. decrease(divide(hpmax Bob) times(10) hp Bob) hp Bob
  67. # now substitute the non-words with words
  68. decrease tally divide of hpmax Bob end times tally 10 end hp Bob end hp Bob
  69. # or if we use and for method chaining
  70. decrease tally divide tally hpmax Bob end and times tally 10 end and hp Bob end and hp Bob
  71. # Conclusion, mere complete inversion is undesirable because the sequence
  72. # becomes unclear, what happens last is set first.
  73. # What is desirable is that like in English the verb comes before the object,
  74. # but only once, UNLESS it's prettier after. So it's better to start out
  75. # quasi-procedural
  76. decrease(hp(Bob), divide(times(hp(Bob), 10), hpmax(Bob)))
  77. #
  78. decrease hp of Bob by call divide call multiply hp of Bob by 10 end with hpmax of Bob end
  79. # of course that sucks somewhat. Probably it would be split up.
  80. # but that's the pricve toi pay to keep thing sipmle.
  81. # Requiring a call/end before most method/function calls resolves the
  82. # bracketing problem, and allows multi-word names, without a symtab.
  83. set newhp to hp of Bob
  84. multiply newhp by 10
  85. divide newhp by hpmax of Bob
  86. # So, raku is a small english like language with an OOP like syntax,
  87. # but no symtab lookup that happens only at runtime.
  88. # The next question is then, how much syntax to provide.
  89. # Since, unlike TCL, I can't use pure string substitutons, some built in constructs are needed.
  90. # However, these can be limited to Smalltalk-level constructs.
  91. # No if/while/etc is really needed, these can be methods in stead.