logo       
Google Custom Search
    AddThis Social Bookmark Button

Some (simple) functions I'd like to see in ExtLib ...: msg#00106

Subject: Some (simple) functions I'd like to see in ExtLib ...
Is it helpful if I produce a patch to implement these?  Or would you
prefer to write the worthy ones yourself?

** Std:

string_of_char c        Equivalent to String.make 1 c

identity x              Just returns x!

unique ()               Returns incrementing integers (has internal state)

input_file filename     Returns the contents of filename as a string

output_file filename str  Writes string str to new/replaced file filename

output_tempfile str     Creates a temporary file, containing str, and returns
                        the filename

unlink_noerr filename   Removes a file, ignoring errors

** ExtChar (or perhaps better in UChar):

is_space, is_alnum, is_digit, is_xdigit, etc.  It's inexplicable why
these were left out of the standard OCaml library.

** ExtList:

List.take n xs          Return first n elements of xs

List.drop n xs          Drop first n elements of xs

List.range a b          Returns the list of integers [a, a+1, ..., b]

List.frequency ?cmp xs  Returns list [f1, x1; f2, x2; ...] where each
                        f1, f2, ... is an integer recording the number of
                        instances of x1, x2, ... in the original list.  My
                        implementation of this assumes xs is sorted already.

List.group_by : ('a * 'b) list -> ('a * 'b list) list

(* This implementation by Isaac Trotts: *)
let group_by ls =
  let ls' =
    List.fold_left
      (fun acc (day1, x1) ->
         match acc with
             [] -> [day1, [x1]]
           | (day2, ls2) :: acctl ->
               if day1 = day2
               then (day1, x1 :: ls2) :: acctl
               else (day1, [x1]) :: acc)
      []
      ls
  in
  let ls' = List.rev ls' in
  List.map (fun (x, xs) -> x, List.rev xs) ls'


** ExtString:

String.contains_string  Returns true if a string contains a substring

A way to replace characters with strings.  I'm going to call this
String.replace, although another name might be preferable.  It should
allow me to do:

let escape_html = String.replace (function '>' -> ">"
                                         | '<' -> "&lt;"
                                         | '&' -> "&amp;"
                                         | c -> string_of_char c)

** Shared

(* A very simple implementation of weak shared strings, by Remi Vanicat *)

module StArg =
struct
  type t = string
  let equal = ( = )
  let hash = Hashtbl.hash
end
module StWeakHash = Weak.Make (StArg)

let table = StWeakHash.create 1024

let shared s =
  try
    StWeakHash.find table s
  with
      Not_found ->
        StWeakHash.add table s;
        s

** CGI functions

I have some common CGI functions which I could donate to ExtLib if
people feel that this is the right place for them.  In particular,
functions for:

* escaping HTML, URLs (see mod_caml's Cgi_escape module, documented
here: http://www.merjis.com/developers/mod_caml/html/Cgi_escape.html )

* parsing query strings

** Date and time handling functions

I have a smallish library of date and time handling functions which
I'm willing to donate if people think that would be useful.  My
library is particularly concerned with the complexity of ISO weeks
[http://en.wikipedia.org/wiki/ISO_8601#Week_-_day_format], but should
probably be extended to do other useful stuff.

** Postscript generation

Another library which I wrote and could donate creates EPS files from
simple drawing commands.

Rich.

-- 
Richard Jones. http://www.annexia.org/ http://www.j-london.com/
Merjis Ltd. http://www.merjis.com/ - improving website return on investment
MOD_CAML lets you run type-safe Objective CAML programs inside the Apache
webserver. http://www.merjis.com/developers/mod_caml/


-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. 
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click



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