text
stringlengths
0
601k
let find t c = let rec aux = function | T . Leaf -> raise Not_found | T . Node ( _ , l , cell , r , _ ) -> let o = compare c cell . cursor in if o = 0 then cell . value else if o < 0 then aux l else aux r in aux t . tree
let position t c0 = let rec traverse n = function | T . Leaf -> raise Not_found | T . Node ( _ , l , cell , r , _ ) -> let o = compare c0 cell . cursor in if o < 0 then traverse n l else let n = n + T . measure l + cell . offset in if o > 0 then traverse n r else n in traverse 0 t . tree
let rec shift_tree n = function | T . Leaf -> T . leaf | T . Node ( _ , T . Leaf , cell , r , _ ) -> T . node T . leaf ( shift_cell n cell ) r | T . Node ( _ , l , cell , r , _ ) -> T . node ( shift_tree n l ) cell r
let shift_tree n tree = if n = 0 then tree else shift_tree n tree
let rem_cursor t c0 = let rec traverse = function | T . Leaf -> raise Not_found | T . Node ( _ , l , cell , r , _ ) -> let o = compare c0 cell . cursor in if o < 0 then let l , shift = traverse l in T . node l ( shift_cell shift cell ) r , 0 else if o > 0 then let r , shift = traverse r in T . node l cell r , shift els...
let put_cursor t ~ at value = if at < 0 then invalid_arg " Trope . put_cursor : [ at ] must be >= 0 " ; let rec traverse before at = function | T . Leaf -> let cursor = O . after before in let cell = make_cell at cursor value in T . node T . leaf cell T . leaf , cursor | T . Node ( _ , l , cell , r , _ ) -> let pos = T...
let insert ? left_of t ~ at ~ len = if at < 0 then invalid_arg " Trope . insert : [ at ] must be >= 0 " ; if len < 0 then invalid_arg " Trope . insert : [ len ] must be >= 0 " ; let right = ( left_of : unit option ) = None in let rec aux n = function | T . Leaf -> T . leaf , len | T . Node ( _ , l , cell , r , _ ) -> l...
let remove ? left_of t ~ at ~ len = if at < 0 then invalid_arg " Trope . remove : [ at ] must be >= 0 " ; if len < 0 then invalid_arg " Trope . remove : [ len ] must be >= 0 " ; if len = 0 then t else let rec rem len = function | T . Leaf -> T . leaf | T . Node ( _ , l , cell , r , _ ) -> let n0 = T . measure l + cell ...
let cursor_at_origin t = O . after t . root
let remove_between t c1 c2 = validate t c1 " Trope . remove_between : cursor not in buffer " ; validate t c2 " Trope . remove_between : cursor not in buffer " ; if c1 == c2 then t else if compare c1 c2 > 0 then invalid_arg " Trope . remove_between : cursors must be in increaing order " else begin let rec cut_left = fun...
let remove_after t c len = validate t c " Trope . remove_after : cursor not in buffer " ; if len < 0 then invalid_arg " Trope . remove_after : len must be >= 0 " else if len = 0 then t else let rec rem n = function | T . Leaf -> T . leaf , n | T . Node ( _ , l , cell , r , _ ) -> let n0 = T . measure l in let n1 = n0 +...
let remove_before t c len = validate t c " Trope . remove_before : cursor not in buffer " ; if len < 0 then invalid_arg " Trope . remove_before : len must be >= 0 " else if len = 0 then t else let rec rem n = function | T . Leaf -> T . leaf | T . Node ( _ , l , cell , r , _ ) -> let n0 = T . measure r in if n <= n0 the...
let insert_before t c len = validate t c " Trope . insert_before : cursor not in buffer " ; if len < 0 then invalid_arg " Trope . insert_before : len must be >= 0 " else if len = 0 then t else let rec aux = function | T . Leaf -> invalid_arg " Trope . insert_before : cursor not in buffer " | T . Node ( _ , l , cell , r...
let insert_after t c len = validate t c " Trope . insert_after : cursor not in buffer " ; if len < 0 then invalid_arg " Trope . insert_after : len must be >= 0 " else if len = 0 then t else let rec aux = function | T . Leaf -> invalid_arg " Trope . insert_after : cursor not in buffer " | T . Node ( _ , l , cell , r , _...
let _put_before t c0 value = validate t c0 " Trope . put_before : cursor not in buffer " ; let aux t = let c = O . before c0 in let rec aux = function | T . Leaf -> invalid_arg " Trope . put_before : cursor not in buffer " | T . Node ( _ , l , cell , r , _ ) -> let i = compare c0 cell . cursor in if i = 0 then T . node...
let _put_after t c0 value = validate t c0 " Trope . put_after : cursor not in buffer " ; let aux t = let c = O . after c0 in let rec aux = function | T . Leaf -> invalid_arg " Trope . put_after : cursor not in buffer " | T . Node ( _ , l , cell , r , _ ) -> let i = compare c0 cell . cursor in if i = 0 then T . node ( T...
let put_left t c v = validate t c " Trope . put_left : cursor from different buffer " ; let rec aux = function | T . Leaf -> T . node T . leaf ( make_cell 0 c v ) T . leaf | T . Node ( _ , l , cell , r , _ ) -> let i = compare c cell . cursor in if i = 0 then T . node l ( make_cell cell . offset c v ) r else if i < 0 t...
let put_right t c v = validate t c " Trope . put_right : cursor from different buffer " ; let rec aux pad = function | T . Leaf -> T . node T . leaf ( make_cell pad c v ) T . leaf , 0 | T . Node ( _ , l , cell , r , _ ) -> let i = compare c cell . cursor in if i = 0 then T . node l ( make_cell cell . offset c v ) r , p...
let find_before t n = let rec aux n = function | T . Leaf -> None | T . Node ( _ , l , cell , r , _ ) -> let n0 = T . measure l + cell . offset in if n < n0 then aux n l else match aux ( n - n0 ) r with | Some _ as result -> result | None -> Some ( cell . cursor , cell . value ) in aux n t . tree
let find_after t n = let rec aux n = function | T . Leaf -> None | T . Node ( _ , l , cell , r , _ ) -> let n0 = T . measure l in if n <= n0 && not ( is_leaf l ) then aux n l else let n1 = n0 + cell . offset in if n <= n1 then Some ( cell . cursor , cell . value ) else aux ( n - n1 ) r in aux n t . tree
let seek_before t c = validate t c " Trope . seek_before : cursor not in buffer " ; let rec aux = function | T . Leaf -> None | T . Node ( _ , l , cell , r , _ ) -> let c = compare c cell . cursor in if c <= 0 then aux l else match aux r with | Some _ as result -> result | None -> Some ( cell . cursor , cell . value ) ...
let seek_after t c = validate t c " Trope . seek_after : cursor not in buffer " ; let rec aux = function | T . Leaf -> None | T . Node ( _ , l , cell , r , _ ) -> let c = compare c cell . cursor in if c >= 0 then aux r else match aux l with | Some _ as result -> result | None -> Some ( cell . cursor , cell . value ) in...
let to_list t = let rec aux acc n = function | T . Leaf -> acc | T . Node ( _ , l , cell , r , _ ) -> let n ' = n + T . measure l + cell . offset in let acc = aux acc n ' r in aux ( ( n ' , cell . cursor , cell . value ) :: acc ) n l in aux [ ] 0 t . tree
module Actions = struct type action = | Incoming_connection_error | Outgoing_connection_error | Gossiped_old_transition of int64 * int | Gossiped_future_transition | Gossiped_invalid_transition | Disconnected_chain | Sent_bad_hash | Sent_invalid_signature | Sent_invalid_transaction | Sent_invalid_proof | Sent_invalid_s...
module Peer_trust = Peer_trust . Make ( Actions ) Actions
let record_envelope_sender : t -> Logger . t -> Network_peer . Envelope . Sender . t -> Actions . t -> unit Deferred . t = fun t logger sender action -> match sender with | Local -> let action_fmt , action_metadata = Actions . to_log action in [ % log debug ] debug ~ metadata ( ( " : action " , ` String action_fmt ) ac...
let subject a = Alcotest . testable ( pp ( Alcotest . pp a ) ) ( equal ( Alcotest . equal a ) ) ; ;
let validate_name ( name , age ) = if String . length name > 1 then Ok ( name , age ) else Error ( Invalid_name name ) ; ;
let validate_age ( name , age ) = if age >= 18 then Ok ( name , age ) else Error ( Invalid_age age ) ; ;
let simple_validation_success ( ) = let open Monad . Infix in let computed = Monad . return ( " Xavier " , 30 ) >>= validate_name >>= validate_age and expected = Ok ( " Xavier " , 30 ) in Alcotest . ( check ( subject ( pair string int ) ) ) " should be valid " expected computed ; ;
let simple_validation_failure_1 ( ) = let open Monad . Infix in let computed = Monad . return ( " X " , 30 ) >>= validate_name >>= validate_age and expected = Error ( Invalid_name " X " ) in Alcotest . ( check ( subject ( pair string int ) ) ) " should be invalid " expected computed ; ;
let simple_validation_failure_2 ( ) = let open Monad . Infix in let computed = Monad . return ( " Xavier " , 17 ) >>= validate_name >>= validate_age and expected = Error ( Invalid_age 17 ) in Alcotest . ( check ( subject ( pair string int ) ) ) " should be invalid " expected computed ; ;
let cases = [ ( " Try " , let open Alcotest in [ test_case " Simple validation with success " ` Quick simple_validation_success ; test_case " Simple validation failure ( for name ) " ` Quick simple_validation_failure_1 ; test_case " Simple validation failure ( for age ) " ` Quick simple_validation_failure_2 ] ) ] ; ;
let print_sexp sexp = Printf . printf " % s \ n " ( sexp |> Sexp . to_string_hum )
let ( ) = Int_conversions . sexp_of_int_style := ` Underscores ; let _info = Info . of_string " foo " in let ivars = ref [ ] in let num_iters = 1_000 in Gc . full_major ( ) ; let minor_before = Gc . minor_words ( ) in let promoted_before = Gc . promoted_words ( ) in for _ = 1 to num_iters do ignore ( try_with ( fun ( )...
let calibrator = force Time_stamp_counter . calibrator
let command = Bench . make_command [ Bench . Test . create ~ name " : Time . now " ( fun ( ) -> ignore ( Time . now ( ) ) ) ; Bench . Test . create ~ name " : Calibrator . calibrate " ( fun ( ) -> ignore ( Time_stamp_counter . Calibrator . calibrate calibrator ) ) ; Bench . Test . create_group ~ name " : Perf " [ Bench...
let id x = x ; ;
let test0 ( ) = ( sscanf " " " " id ) 1 + ( sscanf " " " " id ) 2 + ( sscanf " " " " id ) 3 + ( sscanf " \ t " " " id ) 4 + ( sscanf " \ n " " " id ) 5 + ( sscanf " \ n \ t 6 " " % d " id ) ; ; ; ;
let test1 ( ) = sscanf " 1 " " % d " id + sscanf " 2 " " % d " id + sscanf " - 2 " " % d " id + sscanf " + 2 " " % d " id + sscanf " 2a " " % da " id ; ; ; ;
let test2 ( ) = sscanf " 123 " " % 2i " id + sscanf " 245 " " % d " id + sscanf " 2a " " % 1da " id ; ; ; ;
let test3 ( ) = sscanf " 0xff " " % 3i " id + sscanf " 0XEF " " % 3i " id + sscanf " x =- 245 " " x = % d " id + sscanf " 2a " " % 1da " id ; ; ; ;
let test4 ( ) = bscanf ( Scanning . from_string " 1 " ) " % f " ( fun b0 -> b0 = 1 . 0 ) && bscanf ( Scanning . from_string " - 1 " ) " % f " ( fun b0 -> b0 = - 1 . 0 ) && bscanf ( Scanning . from_string " + 1 " ) " % f " ( fun b0 -> b0 = 1 . 0 ) && bscanf ( Scanning . from_string " 1 . " ) " % f " ( fun b0 -> b0 = 1 ....
let same_float x y = let is_nan z = ( z <> z ) in if is_nan x then is_nan y else Int64 . bits_of_float y = Int64 . bits_of_float x ; ;
let test5 ( ) = bscanf ( Scanning . from_string " 1e1 " ) " % e " ( fun b -> b = 10 . 0 ) && bscanf ( Scanning . from_string " 1e + 1 " ) " % e " ( fun b -> b = 10 . 0 ) && bscanf ( Scanning . from_string " 10e - 1 " ) " % e " ( fun b -> b = 1 . 0 ) && bscanf ( Scanning . from_string " 10 . e - 1 " ) " % e " ( fun b ->...
let test6 ( ) = bscanf ( Scanning . from_string " truetrue " ) " % B % B " ( fun b1 b2 -> ( b1 , b2 ) = ( true , true ) ) && bscanf ( Scanning . from_string " truefalse " ) " % B % B " ( fun b1 b2 -> ( b1 , b2 ) = ( true , false ) ) && bscanf ( Scanning . from_string " falsetrue " ) " % B % B " ( fun b1 b2 -> ( b1 , b2...
let test7 ( ) = bscanf ( Scanning . from_string " ' a ' ' \ n ' ' \ t ' ' \ 000 ' ' \ 032 ' " ) " % C % C % C % C % C " ( fun c1 c2 c3 c4 c5 -> c1 = ' a ' && c2 = ' \ n ' && c3 = ' \ t ' && c4 = ' \ 000 ' && c5 = ' \ 032 ' ) && bscanf ( Scanning . from_string " a \ n \ t \ 000 \ 032b " ) " % c % c % c " ( fun c1 c2 c3 ...
let verify_read c = let s = Printf . sprintf " % C " c in let ib = Scanning . from_string s in assert ( bscanf ib " % C " id = c ) ; ;
let verify_scan_Chars ( ) = for i = 0 to 255 do verify_read ( char_of_int i ) done ; ;
let test8 ( ) = verify_scan_Chars ( ) = ( ) ; ; ; ;
let unit fmt s = let ib = Scanning . from_string ( Printf . sprintf " % S " s ) in Scanf . bscanf ib fmt id ; ;
let test_fmt fmt s = unit fmt s = s ; ;
let test_S = test_fmt " % S " ; ;
let test9 ( ) = test_S " poi " && test_S " a " \ b " && test_S " a \ nb " && test_S " a \ 010b " && test_S " a \\\ n \ b \\\ n \ c \ 010 \\\ n \ b " && test_S " a \\\ n \ \\\ n \ \\\ n \ b \\\ n \ c \ 010 \\\ n \ b " && test_S " \ xef " && test_S " \\ xef " && Scanf . sscanf " " \\\ xef " " \ " % S " ( fun s -> s ) = "...
let test10 ( ) = let unit s = let ib = Scanning . from_string s in Scanf . bscanf ib " % S " id in let res = sscanf " Une chaine : " \ celle - ci " \ et " \ celle - la " " \! " % s % s % S % s % S % s " ( fun s1 s2 s3 s4 s5 s6 -> s1 ^ s2 ^ s3 ^ s4 ^ s5 ^ s6 ) in res = " Unechaine : celle - cietcelle - la " ! && unit " ...
let test11 ( ) = sscanf " Pierre \ tWeis \ t70 " " % s % s % s " ( fun prenom nom poids -> prenom = " Pierre " && nom = " Weis " && int_of_string poids = 70 ) && sscanf " Jean - Luc \ tde Leage \ t68 " " [ %^\ t ] [ %^\ t ] % d " ( fun prenom nom poids -> prenom = " Jean - Luc " && nom = " de Leage " && poids = 68 ) &&...
let test110 ( ) = sscanf " " " " ( fun x -> x ) " " = " " && sscanf " " " % s " ( fun x -> x = " " ) && sscanf " " " % s % s " ( fun x y -> x = " " && y = " " ) && sscanf " " " % s " ( fun x -> x = " " ) && sscanf " " " % s " ( fun x -> x = " " ) && sscanf " " " % s " ( fun x -> x = " " ) && sscanf " " " [ %^\ n ] " ( ...
let test111 ( ) = sscanf " " " [ %^\ n ] @\ n " ( fun x -> x = " " ) ; ; ; ;
let ib ( ) = Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ; ] " ; ;
let f ib = bscanf ib " [ " ( ) ; bscanf ib " % i ; " ( fun i -> bscanf ib " % i ; " ( fun j -> bscanf ib " % i ; " ( fun k -> bscanf ib " % i ; " ( fun l -> bscanf ib " ] " ( ) ; [ i ; j ; k ; l ] ) ) ) ) ; ;
let test12 ( ) = f ( ib ( ) ) = [ 1 ; 2 ; 3 ; 4 ] ; ; ; ;
let rec scan_elems ib accu = try bscanf ib " % i ; " ( fun i -> scan_elems ib ( i :: accu ) ) with | _ -> accu ; ;
let g ib = bscanf ib " [ " ( ) ; List . rev ( scan_elems ib [ ] ) ; ;
let test13 ( ) = g ( ib ( ) ) = [ 1 ; 2 ; 3 ; 4 ] ; ; ; ;
let rec scan_int_list ib = bscanf ib " [ " ( ) ; let accu = scan_elems ib [ ] in bscanf ib " ] " ( ) ; List . rev accu ; ;
let test14 ( ) = scan_int_list ( ib ( ) ) = [ 1 ; 2 ; 3 ; 4 ] ; ; ; ;
let rec scan_elems ib accu = bscanf ib " % i % c " ( fun i -> function | ' ; ' -> scan_elems ib ( i :: accu ) | ' ] ' -> List . rev ( i :: accu ) | c -> failwith " scan_elems " ) ; ;
let rec scan_int_list ib = bscanf ib " [ " ( ) ; scan_elems ib [ ] ; ;
let test15 ( ) = scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ] " ) = [ 1 ; 2 ; 3 ; 4 ] ; ; ; ;
let rec scan_elems ib accu = try bscanf ib " % c % i " ( fun c i -> match c with | ' ; ' -> scan_elems ib ( i :: accu ) | ' ] ' -> List . rev ( i :: accu ) | ' [ ' when accu = [ ] -> scan_elems ib ( i :: accu ) | c -> print_endline ( String . make 1 c ) ; failwith " scan_elems " ) with | Scan_failure _ -> bscanf ib " ]...
let scan_int_list ib = scan_elems ib [ ] ; ;
let test16 ( ) = scan_int_list ( Scanning . from_string " [ ] " ) = List . rev [ ] && scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ] " ) = List . rev [ 1 ; 2 ; 3 ; 4 ] && scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ; ] " ) = List . rev [ 1 ; 2 ; 3 ; 4 ] && scan_int_list ( Scanning . from_string...
let rec scan_elems ib accu = bscanf ib " % i [ ] ; % \ t \ n \ r ] " ( fun i s -> match s with | " ; " -> scan_elems ib ( i :: accu ) | " ] " -> List . rev ( i :: accu ) | s -> List . rev ( i :: accu ) ) ; ;
let scan_int_list ib = bscanf ib " [ " ( ) ; scan_elems ib [ ] ; ;
let test17 ( ) = scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ] " ) = [ 1 ; 2 ; 3 ; 4 ] && scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ; ] " ) = [ 1 ; 2 ; 3 ; 4 ] && scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 5 ] " ) = [ 1 ; 2 ; 3 ; 4 ] ; ; ; ;
let rec scan_elems ib accu = bscanf ib " % c " ( fun c -> match c with | ' [ ' when accu = [ ] -> bscanf ib " [ ] ] " % ( function | " ] " -> accu | _ -> bscanf ib " % i " ( fun i -> scan_rest ib ( i :: accu ) ) ) | _ -> failwith " scan_elems " ) bscanf ib " % c " ( fun c -> match c with | ' ; ' -> bscanf ib " [ ] ] " ...
let scan_int_list ib = List . rev ( scan_elems ib [ ] ) ; ;
let test18 ( ) = scan_int_list ( Scanning . from_string " [ ] " ) = [ ] && scan_int_list ( Scanning . from_string " [ ] " ) = [ ] && scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ] " ) = [ 1 ; 2 ; 3 ; 4 ] && scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ; ] " ) = [ 1 ; 2 ; 3 ; 4 ] ; ; ; ;
let test19 ( ) = failure_test scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 5 ] " ) " scan_rest " ; ; ; ;
let test20 ( ) = scan_failure_test scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ; ; 5 ] " ) ; ; ; ;
let test21 ( ) = scan_failure_test scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ; ; " ) ; ; ; ;
let rec scan_elems ib accu = bscanf ib " % 1 [ ] ; ] " ( function | " ] " -> accu | " ; " -> scan_rest ib accu | _ -> failwith ( Printf . sprintf " scan_int_list " ) ) bscanf ib " [ ] ] " % ( function | " ] " -> accu | _ -> scan_elem ib accu ) bscanf ib " % i " ( fun i -> scan_elems ib ( i :: accu ) ) ; ;
let scan_int_list ib = bscanf ib " [ " ( ) ; List . rev ( scan_rest ib [ ] ) ; ;
let test22 ( ) = scan_int_list ( Scanning . from_string " [ ] " ) = [ ] && scan_int_list ( Scanning . from_string " [ ] " ) = [ ] && scan_int_list ( Scanning . from_string " [ 1 ] " ) = [ 1 ] && scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ] " ) = [ 1 ; 2 ; 3 ; 4 ] && scan_int_list ( Scanning . from_string ...
let rec scan_elems ib accu = try bscanf ib " % i % 1 [ ; ] " ( fun i s -> if s = " " then i :: accu else scan_elems ib ( i :: accu ) ) with | Scan_failure _ -> accu ; ;
let rec scan_int_list ib = bscanf ib " [ " ( ) ; let accu = scan_elems ib [ ] in bscanf ib " ] " ( ) ; List . rev accu ; ;
let rec scan_elems ib scan_elem accu = try scan_elem ib ( fun i s -> let accu = i :: accu in if s = " " then accu else scan_elems ib scan_elem accu ) with | Scan_failure _ -> accu ; ;
let scan_list scan_elem ib = bscanf ib " [ " ( ) ; let accu = scan_elems ib scan_elem [ ] in bscanf ib " ] " ( ) ; List . rev accu ; ;
let scan_int_elem ib = bscanf ib " % i % 1 [ ; ] " ; ;
let scan_int_list = scan_list scan_int_elem ; ;
let test23 ( ) = scan_int_list ( Scanning . from_string " [ ] " ) = [ ] && scan_int_list ( Scanning . from_string " [ ] " ) = [ ] && scan_int_list ( Scanning . from_string " [ 1 ] " ) = [ 1 ] && scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ] " ) = [ 1 ; 2 ; 3 ; 4 ] && scan_int_list ( Scanning . from_string ...
let test24 ( ) = scan_failure_test scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 5 ] " ) scan_failure_test scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ; ; " ) scan_failure_test scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ; ; 5 ] " ) scan_failure_test scan_int_list ( Scanning . from_...
let scan_string_elem ib = bscanf ib " " \% s " @\ % 1 [ ; ] " ; ;
let scan_string_list = scan_list scan_string_elem ; ;
let scan_String_elem ib = bscanf ib " % S % 1 [ ; ] " ; ;
let scan_String_list = scan_list scan_String_elem ; ;
let test28 ( ) = scan_string_list ( Scanning . from_string " [ ] " ) = [ ] && scan_string_list ( Scanning . from_string " [ " \ Le " ] " ) \ = [ " Le " ] && scan_string_list ( Scanning . from_string " [ " \ Le " ; " \\ langage " ; " \\ Objective " ; " \\ Caml " ] " ) \ = [ " Le " ; " langage " ; " Objective " ; " Caml ...
let rec scan_elems ib scan_elem accu = scan_elem ib ( fun i s -> let accu = i :: accu in if s = " " then accu else scan_elems ib scan_elem accu ) ( fun ib exc -> accu ) ; ;
let scan_list scan_elem ib = bscanf ib " [ " ( ) ; let accu = scan_elems ib scan_elem [ ] in bscanf ib " ] " ( ) ; List . rev accu ; ;
let scan_int_elem ib f ek = kscanf ib ek " % i % 1 [ ; ] " f ; ;