Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Dynamically evaluating OCaml code
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Fernando Alegre <fernando@c...>
Subject: Re: [Caml-list] Dynamically evaluating OCaml code
On Thu, Apr 08, 2004 at 08:37:27AM -0500, John Goerzen wrote:

> Basic string processing is also more difficult than a language such as,
> say, Python, where I can say, for instance:
> 
> y = x[2:-1]
> 
> In OCaml, I would write -- I think:
> 
> let y = String.sub x 2 ((String.length x) - 3))
> 

You can always use the ability of Ocaml to create new operators to
partially overcome this problem:

# let ($<) s i = String.sub s 0 i;;
val ( $< ) : string -> int -> string = <fun>

# let ($>) s i = String.sub s (String.length s - i) i;;
val ( $> ) : string -> int -> string = <fun>

# "hello, world" $< 5 $> 3;;
- : string = "llo"

# "hello, world" $> 5 $< 3;;
- : string = "wor"

Fernando

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners