Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] unix.chop_extension
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Xavier Leroy <xavier.leroy@i...>
Subject: Re: [Caml-list] unix.chop_extension
John Skaller writes:

> # Filename.chop_extension "x.y/z";;
> - : string = "x"
> 
> Oh come on. This is correct according to the specs,
> but no one would believe this function is chopping
> off the extension here :)

Care to submit a bug report for that?

> Also 
> let y = (concat (directory x) (basename x)) in
> assert x = y
> is not guarranteed, only that x,y are 'equivalent'.
> What does that mean?

That both names (x and y) refer to the same file.  You access the same
file if you open one or the other.

Alex Baretta writes:

> This is a terrible consequence of not having (* functional *) support 
> for regexps in the language or standard library. [...]
> The Str module has a very clever implementation, but it cannot be used 
> systematically in Ocaml because it is not *functional*. I'm sure that if 
> we had a functional version of Str, the author of the Filename module 
> would rewrite it using regular expressions instead of the rindex function.

You're jumping to conclusions here.  Str is an external library, not
part of the standard library (stdlib).  The way the OCaml distribution
is set up, stdlib code can only refer to other stdlib modules; the
compilers and tools can use stdlib and their own modules; and other
libraries such as Str are outside the stdlib/compiler subset.  This
stratification is important because of bootstrapping issues.  It's
always a good idea to minimize the bootstrapping base, which currently
consists of stdlib, ocamlc and ocamllex.

So, it's true that parts of stdlib and the compilers would benefit
from regexps (see e.g. asmcomp/asmpackager.ml), but the reason for not
using regexps has nothing to do with the imperative interface of Str.

Concerning the Str interface, I received several complaints about it,
to which I replied "why don't you propose an alternate functional API?",
to which I never got any reply.  So, if you have ideas, go ahead.  If
you can get some peer reviewing on your design, that would be much better.
Good APIs aren't easy to design (witness the lengthy discussion on I/O
on this list), so it's unlikely that you can find a good one all by
yourself in 30 minutes.

> There's one extra thing I'd like to point out. We have the 
> chop_extension function. Why in the world is there no find_extension 
> function?
> find_extension "foo.bar" --> "bar"

Why in the world would that be generally useful?  Remember, we don't
shoot for completeness (it's unattainable anyway), just for
usefulness.

- Xavier Leroy

-------------------
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