Commit 1b72582ee990eef61fe5484ed3cffa69e8fca2f1
1 parent
33d50df7
[+] add map_compute function which allow map with a dynamic parameter.
Showing
1 changed file
with
23 additions
and
2 deletions
Show diff stats
anubis_dev/library/tools/function.anubis
@@ -254,7 +254,28 @@ public define List($C) | @@ -254,7 +254,28 @@ public define List($C) | ||
254 | [x . map_parameter(f, p1, t)] | 254 | [x . map_parameter(f, p1, t)] |
255 | } | 255 | } |
256 | . | 256 | . |
257 | - | 257 | + |
258 | +public define $P | ||
259 | +/** 'map' with a dynamic parameter. A new parameter is return as a result and | ||
260 | + * pass through as parameter with next call iteration and finally returned as | ||
261 | + * result of the map_parameter. This allows to make computation on the parameter | ||
262 | + * like a sum | ||
263 | + */ | ||
264 | + map_compute | ||
265 | + ( | ||
266 | + ($P,$B) -> $P f, // | ||
267 | + $P p, //initial parameter | ||
268 | + List($B) l // | ||
269 | + ) = | ||
270 | + if l is | ||
271 | + { | ||
272 | + [ ] then p, | ||
273 | + [h . t] then | ||
274 | + with p1 = f(p, h), | ||
275 | + map_compute(f, p1, t) | ||
276 | + } | ||
277 | +. | ||
278 | + | ||
258 | public define List($C) | 279 | public define List($C) |
259 | /** 'map' with a dynamic parameter. A new parameter is return with the result and | 280 | /** 'map' with a dynamic parameter. A new parameter is return with the result and |
260 | * pass through as parameter with next call iteration | 281 | * pass through as parameter with next call iteration |
@@ -669,4 +690,4 @@ public define macro $T | @@ -669,4 +690,4 @@ public define macro $T | ||
669 | (($T t) |-f-> if test(t) then f(step(t)) else t)(init). // terminal call ! | 690 | (($T t) |-f-> if test(t) then f(step(t)) else t)(init). // terminal call ! |
670 | 691 | ||
671 | 692 | ||
672 | - | ||
673 | \ No newline at end of file | 693 | \ No newline at end of file |
694 | + |