| 1 | import((vile,base)) |
| 2 | define-syntax(skip-even,syntax-rules((),((_,discarded),continue()))) |
| 3 | sum-odds(n) := { |
| 4 | total := 0 |
| 5 | for(i := 0, i < n, i = i + 1) { |
| 6 | if even?(i) { skip-even(missing) } |
| 7 | total = total + i |
| 8 | } |
| 9 | total |
| 10 | } |
| 11 | find-negative(xs) := { |
| 12 | hit := #f |
| 13 | for(i := 0, i < vector-length(xs), i = i + 1) { |
| 14 | if xs[i] < 0 { hit = i, break } |
| 15 | } |
| 16 | return(hit) |
| 17 | missing |
| 18 | } |
| 19 | capture-loop-locals() := { |
| 20 | fs := list() |
| 21 | for(i := 0, i < 3, i = i + 1) { |
| 22 | x := i |
| 23 | fs = cons(fn(){x},fs) |
| 24 | continue |
| 25 | } |
| 26 | map(fn(f){f()},fs) |
| 27 | } |
| 28 | list(sum-odds(10),find-negative([1,2,-3,4]),capture-loop-locals(), |
| 29 | let((continue(+),break(*)),list(continue(20,22),break(6,7)))) |
| 30 | |