From f4dcb389fd6a760c2b5c1d772b93120c87b54869 Mon Sep 17 00:00:00 2001 From: martinw Date: Fri, 27 Apr 2001 09:48:47 +0000 Subject: added handy new macro for searching lists git-svn-id: https://svn.cs.ru.nl/repos/clean-compiler/trunk@373 1f8540f1-abd5-4d5b-9d24-4c5ce8603e2d --- frontend/utilities.dcl | 11 +++++++++++ frontend/utilities.icl | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/frontend/utilities.dcl b/frontend/utilities.dcl index 9d92475..232330c 100644 --- a/frontend/utilities.dcl +++ b/frontend/utilities.dcl @@ -180,6 +180,17 @@ foldrArraySt f a st # (ai, a) = a![i] = foldr_a_st (i-1) a (f ai st) + +firstIndex p l :== first_index l 0 + where + first_index [] i + = (i-i)-1 + first_index [h:t] i + | p h + = i + = first_index t (i+1) + + optCons :: !(Optional .a) !u:[.a] -> (!v:[.a], !Int) ,[u <= v] revAppend :: ![a] ![a] -> [a] // Reverse the list using the second argument as accumulator. diff --git a/frontend/utilities.icl b/frontend/utilities.icl index 6b5f09c..3ceb48b 100644 --- a/frontend/utilities.icl +++ b/frontend/utilities.icl @@ -266,6 +266,15 @@ foldrArraySt f a st # (ai, a) = a![i] = foldr_a_st (i-1) a (f ai st) +firstIndex p l :== first_index l 0 + where + first_index [] i + = (i-i)-1 + first_index [h:t] i + | p h + = i + = first_index t (i+1) + optCons :: !(Optional .a) !u:[.a] -> (!v:[.a], !Int) ,[u <= v] optCons No l = (l, 0) -- cgit v1.2.3