# HG changeset patch # User Mike Pavone # Date 1280533711 0 # Node ID 6d41b71f1b77d8b7dbac53e8cfbedf9d72b7bc8b # Parent 27bb051d631c469845de74894ed7e135d6757ae7 Add Map, Filter and Find diff -r 27bb051d631c -r 6d41b71f1b77 functional.rhope --- a/functional.rhope Tue Jul 27 23:33:31 2010 -0400 +++ b/functional.rhope Fri Jul 30 23:48:31 2010 +0000 @@ -21,3 +21,73 @@ } } +_Map[list,worker,cur:out] +{ + val <- [list]Index[cur] + nlist <- [list]Set[cur, [worker]Call[val, cur]] + + [nlist]Next[cur] + { + out <- _Map[nlist, worker, ~] + }{ + out <- Val[nlist] + } +} + +Map[list,worker:out] +{ + [list]First + { + out <- _Map[list,worker,~] + }{ + out <- list + } +} + +_Find[list,pred,cur:loc,not found] +{ + val <- [list]Index[cur] + If[[pred]Call[val]] + { + loc <- cur + }{ + ,not found <- [list]Next[cur] + { loc,not found <- _Find[list,pred,~] } + } +} + +Find[list,pred:loc,not found] +{ + ,not found <- [list]First + { + loc <- _Find[list,pred,~] + } +} + +_Filter[list,pred,cur,dest:out] +{ + val <- [list]Index[cur] + If[[pred]Call[val,cur]] + { + ndest <- [dest]Append[val] + }{ + ndest <- dest + } + [list]Next[cur] + { + out <- _Filter[list,pred,~,ndest] + }{ + out <- Val[ndest] + } +} + +Filter[list,pred:out] +{ + [list]First + { + out <- _Filter[list,pred,~, List[]] + }{ + out <- list + } +} +