The article is written in OCaml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
let is_palindrome s =
    let l = String.length s in
    let rec comp n =
        n = 0 || (s.[l-n] = s.[n-1] && comp (n-1)) in
    comp (l / 2)

let rem_space str =
  let len = String.length str in
  let res = String.create len in
  let rec aux i j =
    if i >= len
    then (String.sub res 0 j)
    else match str.[i] with
    | ' ' | '\n' | '\t' | '\r' ->
        aux (i+1) (j)
    | _ ->
        res.[j] <- str.[i];
        aux (i+1) (j+1)
  in
  aux 0 0