src/Pure/library.ML
changeset 39809 dac3c3106746
parent 39616 8052101883c3
child 39811 0659e84bdc5f
     1.1 --- a/src/Pure/library.ML	Thu Sep 30 09:45:18 2010 +0200
     1.2 +++ b/src/Pure/library.ML	Thu Sep 30 18:37:29 2010 +0200
     1.3 @@ -83,7 +83,8 @@
     1.4    val take: int -> 'a list -> 'a list
     1.5    val drop: int -> 'a list -> 'a list
     1.6    val chop: int -> 'a list -> 'a list * 'a list
     1.7 -  val dropwhile: ('a -> bool) -> 'a list -> 'a list
     1.8 +  val take_while: ('a -> bool) -> 'a list -> 'a list
     1.9 +  val drop_while: ('a -> bool) -> 'a list -> 'a list
    1.10    val nth: 'a list -> int -> 'a
    1.11    val nth_map: int -> ('a -> 'a) -> 'a list -> 'a list
    1.12    val nth_drop: int -> 'a list -> 'a list
    1.13 @@ -421,8 +422,11 @@
    1.14    | chop _ [] = ([], [])
    1.15    | chop n (x :: xs) = chop (n - 1) xs |>> cons x;
    1.16  
    1.17 -fun dropwhile P [] = []
    1.18 -  | dropwhile P (ys as x::xs) = if P x then dropwhile P xs else ys;
    1.19 +fun drop_while P [] = []
    1.20 +  | drop_while P (ys as x :: xs) = if P x then drop_while P xs else ys;
    1.21 +
    1.22 +fun take_while P [] = []
    1.23 +  | take_while P (x :: xs) = if P x then x :: take_while P xs else [];
    1.24  
    1.25  (*return nth element of a list, where 0 designates the first element;
    1.26    raise Subscript if list too short*)