Explorar el Código

more on flow control statements

tcheukueppo hace 2 años
padre
commit
2ab7869849
Se han modificado 1 ficheros con 73 adiciones y 12 borrados
  1. 73 12
      hacking_pity/pity.md

+ 73 - 12
hacking_pity/pity.md

@@ -260,8 +260,8 @@ We donot expand type 2 special variables with `$`
 Pity has 16 builtin objects, types are objects and objects are types, check details of
 Pity has 16 builtin objects, types are objects and objects are types, check details of
 each types here.
 each types here.
 
 
-- Pity (itself is an object)
 - Bool (Booleans)
 - Bool (Booleans)
+- Pity (pity is an object itself)
 - Num (Big integers and Big floats)
 - Num (Big integers and Big floats)
 - Rat (Rationals)
 - Rat (Rationals)
 - Str (Strings)
 - Str (Strings)
@@ -276,12 +276,14 @@ each types here.
 - Socket (Sockets)
 - Socket (Sockets)
 - Regex (regular expressions)
 - Regex (regular expressions)
 - Range (Range object)
 - Range (Range object)
+- Date (perform operations on date)
 
 
 # Flow control
 # Flow control
 
 
-Here is an overview of pity syntax
-We separate statements with a generic line or a semicolon in case we have more
-than one statements on a single line.
+Here is an overview of the pity syntax.
+
+We separate statements with a generic newline or a semicolon in case we have more
+than one statement on a single line.
 
 
 1. Blocks
 1. Blocks
 
 
@@ -298,7 +300,6 @@ say 2; say 3
 
 
 2. `do` Block
 2. `do` Block
 
 
-`do` block
 ```raku
 ```raku
 let v = do { 2 }
 let v = do { 2 }
 # "2"
 # "2"
@@ -314,7 +315,7 @@ do { false } or die "failed"
 
 
 run a block asyncronously
 run a block asyncronously
 
 
-```raku
+```javascript
 async {
 async {
     sleep 4 && say "done"
     sleep 4 && say "done"
 }
 }
@@ -356,19 +357,23 @@ Conditional `with` statement, parathensis are always optional.
 
 
 ```raku
 ```raku
 
 
-let (x, y) = (5, nil)
+let (u, y) = (5, nil)
 
 
-with(x) { say _ }
+# 5, 5
+with u { say _, x }
 
 
-with(y)   { say "never here" }
-orwith(y) {:m say m }
-else      { say "never here" }
+# 5
+with   y { say "never here" }
+orwith u {:m say m }
+else     { say "never here" }
 ```
 ```
 
 
 6. `for`
 6. `for`
 
 
 ```ruby
 ```ruby
-ar = qw(one two three four five)
+ar = <one two three four five>
+
+for "a", qr/regex/, [2, 4] { .say }
 
 
 # output: 3 3 5 4 4
 # output: 3 3 5 4 4
 for ar -> i { i.len.say }
 for ar -> i { i.len.say }
@@ -386,6 +391,62 @@ for ar -> i, j { say "(#i, #j)" }
 for ar -> i, j = "none" { say "(#i, #j)" }
 for ar -> i, j = "none" { say "(#i, #j)" }
 ```
 ```
 
 
+7. `gather`-`take`
+
+statement/block prefix which returns a sequence of values comming from calls to take in
+the dynamic scope of code passed as argument to gather.
+
+```raku
+fun factors(n) {
+  let k = 1
+  gather {
+    while k ** 2 < n {
+        if n % k {
+            take k
+            take n.div(k)
+        }
+        k++
+    }
+    take k if k ** 2 == n
+  }
+}
+
+factors(36).say
+```
+
+8. `given`-`when`
+
+
+```raku
+given 34 {
+  when Num { say "Num" }
+  when 42  { say "42" }
+  default  { say "Default" }
+}
+```
+
+10. `loop`
+
+just like the C-for loop
+
+general form: `loop initialization; condition; step { ... }`
+
+```raku
+let k
+
+loop k = 0; k <= 20; k++ { }
+```
+
+12. `while`, `until`
+
+13. `repeat` `while`/`until`
+
+14. `LABELS`
+
+15. `once`
+
+16. `next`, `break`, `redo`
+
 # Functions
 # Functions
 
 
 # Classes
 # Classes