comparison modules/range.tp @ 343:21e20c9bb2ba

Added range module and sample
author Michael Pavone <pavone@retrodev.com>
date Sun, 05 Apr 2015 23:35:05 -0700
parents
children
comparison
equal deleted inserted replaced
342:884cd5d54c0f 343:21e20c9bb2ba
1 #{
2 from:to:by <- :_from :_to :_by {
3 #{
4 from <- { _from }
5 to <- { _to }
6 by <- { _by }
7
8 legnth <- { (_to - _from) / _by }
9
10 get <- :idx { _to + idx * _by}
11
12 array <- {
13 fold: #[] with: :acc el {
14 acc append: el
15 }
16 }
17
18 list <- {
19 map: :el { el }
20 }
21
22 map <- :fun {
23 foldr: [] with: :acc el {
24 (fun: el) | acc
25 }
26 }
27
28 foldr:with <- :acc :fun {
29 cur <- _from + ((_to - _from) / _by) * _by
30 while: { cur >= _from } do: {
31 acc <- fun: acc cur
32
33 cur <- cur - _by
34 }
35 acc
36 }
37
38 fold:with <- :acc :fun {
39 cur <- _from
40 while: { cur < _to } do: {
41 acc <- fun: acc cur
42
43 cur <- cur + _by
44 }
45 acc
46 }
47
48 foreach <- :fun {
49 idx <- 0
50 cur <- _from
51 res <- cur
52 while: { cur < _to} do: {
53 res <- fun: idx cur
54
55 idx <- idx + 1
56 cur <- cur + _by
57 }
58 res
59 }
60 }
61 }
62
63 from:to <- :f :t { from: f to: t by: 1 }
64 }