introduction.raku 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # Introduction to the Raku scripting Language. This is a comment.
  2. #--- And so is this.
  3. This is a multi line comment
  4. ---#
  5. # Blank lines are generally ignored matter
  6. # This is a simple command call with a string argument
  7. say "hello"
  8. # assignment and arithmetic operators are supported and keep their precedence
  9. # floating point and integer numbers are supported
  10. a = 5 + 7.0 * -3.14
  11. # Statements can be grouped between brackets or braces into blocks
  12. # Block statements must be terminated by new lines or semicolons
  13. [ say "First" ; say "Second" ; Say "third" ;]
  14. { say "First" ; say "Second" ; Say "third" ;}
  15. {
  16. say "First"
  17. say "Second"
  18. say "Third"
  19. }
  20. # A parenthesis block may only contain a single statement.
  21. ( a + sqrt 2.0 )
  22. # But it can be used as arguments to a command, or in an operator expression
  23. z = ( a * sqrt 2.0 ) + (b * sqrt 3.0 )
  24. # A block can be passed to a command as an argument
  25. repeat 3 {
  26. say "Repeat"
  27. }
  28. a > b
  29. # Control statements are just normal commands with block arguments
  30. if ( a > 10 ) {
  31. say "Greater"
  32. } else { # Watch out, no newline is allowed before the "else", or the "else" would become a separate command.
  33. say "Lesser"
  34. }
  35. # Define a new command like this:
  36. def say_hello [] {
  37. say "Hello!"
  38. }
  39. #---
  40. set aa b
  41. set foobar to 10
  42. # set the foobar's pianos' size to 10 + 10
  43. open the door at the front .
  44. cast cure at the big green dog behind the red door.
  45. # loop for i from -1 to 10 do
  46. # print i
  47. # print i * 2
  48. # end
  49. # check length of foo equals 5 and bar's size equals 7 do
  50. # print "foo OK"
  51. # end else do
  52. # print "not foo OK"
  53. # end
  54. # 10 + 10
  55. # set foobar to the the 10 + 10
  56. # type Being is an Object do
  57. # field its name is a String
  58. # field its hp is an Integer
  59. # field its hpx is an Integer
  60. # end
  61. make Being
  62. # set foo expr not expr bar and baz end end
  63. set foo to 10
  64. cast cure light beastly fido
  65. cast cure light at beastly fido
  66. # set foo to ( 1 lshift 2 binand 78 rshift 1) greater_or_equal 77
  67. set bar to true or false
  68. ---#