From: Richard J. <ri...@an...> - 2006-02-27 12:01:25
|
Currently, String.nsplit "" _ returns a single element list: $ ocaml -I +extlib Objective Caml version 3.08.3 # #load "unix.cma";; # #load "extLib.cma";; # open ExtString;; # String.nsplit "" ",";; - : string list = [""] # String.nsplit "execute" ",";; - : string list = ["execute"] I would argue, however, that it'd be much better if it acted like Perl's split and this was special-cased to return a zero-length list: $ perl -MData::Dumper -e 'print (Dumper (split /,/, ""))' $ perl -MData::Dumper -e 'print (Dumper (split /,/, "execute"))' --> $VAR1 = 'execute'; $ perl -MData::Dumper -e 'print (Dumper (split /,/, "execute,him"))' --> $VAR1 = 'execute'; $VAR2 = 'him'; The reason is that otherwise you need a special case when dealing with lists of flags, for example: let f ?(flags = "") () = let flags = String.nsplit flags "," in (* following doesn't work because if there are no flags, the * inner function is called once with a "" argument *) List.iter ( fun flag -> (* handle it *) ) flags; Rich. -- Richard Jones, CTO Merjis Ltd. Merjis - web marketing and technology - http://merjis.com Team Notepad - intranets and extranets for business - http://team-notepad.com |