src/Pure/library.ML
changeset 4713 bea2ab2e360b
parent 4692 748f4e365d14
child 4792 8e3c2dddb9c8
equal deleted inserted replaced
4712:facfbbca7242 4713:bea2ab2e360b
    74   val foldr: ('a * 'b -> 'b) -> 'a list * 'b -> 'b
    74   val foldr: ('a * 'b -> 'b) -> 'a list * 'b -> 'b
    75   val foldr1: ('a * 'a -> 'a) -> 'a list -> 'a
    75   val foldr1: ('a * 'a -> 'a) -> 'a list -> 'a
    76   val length: 'a list -> int
    76   val length: 'a list -> int
    77   val take: int * 'a list -> 'a list
    77   val take: int * 'a list -> 'a list
    78   val drop: int * 'a list -> 'a list
    78   val drop: int * 'a list -> 'a list
       
    79   val dropwhile: ('a -> bool) -> 'a list -> 'a list
    79   val nth_elem: int * 'a list -> 'a
    80   val nth_elem: int * 'a list -> 'a
    80   val last_elem: 'a list -> 'a
    81   val last_elem: 'a list -> 'a
    81   val split_last: 'a list -> 'a list * 'a
    82   val split_last: 'a list -> 'a list * 'a
    82   val find_index: ('a -> bool) -> 'a list -> int
    83   val find_index: ('a -> bool) -> 'a list -> int
    83   val find_index_eq: ''a -> ''a list -> int
    84   val find_index_eq: ''a -> ''a list -> int
   422 (*drop the first n elements from a list*)
   423 (*drop the first n elements from a list*)
   423 fun drop (n, []) = []
   424 fun drop (n, []) = []
   424   | drop (n, x :: xs) =
   425   | drop (n, x :: xs) =
   425       if n > 0 then drop (n - 1, xs) else x :: xs;
   426       if n > 0 then drop (n - 1, xs) else x :: xs;
   426 
   427 
       
   428 fun dropwhile P [] = []
       
   429   | dropwhile P (ys as x::xs) = if P x then dropwhile P xs else ys;
       
   430 
   427 (*return nth element of a list, where 0 designates the first element;
   431 (*return nth element of a list, where 0 designates the first element;
   428   raise EXCEPTION if list too short*)
   432   raise EXCEPTION if list too short*)
   429 fun nth_elem NL =
   433 fun nth_elem NL =
   430   (case drop NL of
   434   (case drop NL of
   431     [] => raise LIST "nth_elem"
   435     [] => raise LIST "nth_elem"