Using regular expressions to validate a numeric range

Using regular expressions to validate a numeric range To be clear: When a simple if statement will suffice if(num < -2055 || num > 2055) { throw new IllegalArgumentException(“num (” + num + “) must be between -2055 and 2055”); } using regular expressions for validating numeric ranges is not recommended. In addition, since regular … Read more

Print a List in OCaml

You should become familiar with the List.iter and List.map functions. They are essential for programming in OCaml. If you also get comfortable with the Printf module, you can then write: open Printf let a = [1;2;3;4;5] let () = List.iter (printf “%d “) a I open Printf in most of my code because I use … Read more

Calling OCaml-wrapped ZeroMQ code from signal handler

There are two potential problems: Inside a signal handler, you can only call asynchronous signal safe functions. Most functions are not async signal safe. The reason for the restriction is that a function could be called in the middle of the same function’s execution. Thus, internal state could be corrupted. Very few functions are async … Read more

What is the state of OCaml’s parallelization abilities?

This 2009 issue of the Caml weekly news (“CWN”, a digest of interesting messages from the caml list) shows that: the official party line on threads and Ocaml hasn’t changed. A notable quote: (…) in general, the whole standard library is not thread-safe. Probably that should be stated in the documentation for the threads library, … Read more