logo       
Google Custom Search
    AddThis Social Bookmark Button

String.nsplit empty string: msg#00002

Subject: String.nsplit empty string
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


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642



Try Searching:
servers, voip, java, networking, microsoft ...
<Prev in Thread] Current Thread [Next in Thread>