Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Bug in Filename.basename?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-09-05 (20:39)
From: Oliver Bandel <oliver@f...>
Subject: Re: [Caml-list] Bug in Filename.basename?
Zitat von Erik de Castro Lopo <>:

> Oliver Bandel wrote:
> > But possibly it's not different to other basename-implementations.
> Which is exactly what I said later in my email.

No, you showed two examples.
Did you tested other systems/implementations also?

Even if all results are the same, it doesn't matter,
because you compare things that can't be compared.

Switch on your mental type checking ;-)

> > Looking at that documentation, I can't see no bug in the implementation.
> Your documentation documents the Ocaml function.

Yes, and you asked for the behaviour of the OCaml function,
so I did read the right documentation.

You preassumed, that OCaml's Filename.basename has to implement
a basename-function that you want, but this is nonsense.

> > When you want to know how your car's GPS-navigation system works,
> > do you look in the documentation of your video-camera or vacuum-cleaner?
> We are not talking about GPS systems or video cameras or vacuum cleaners,
> but if you want we can continue;

it seems, that you want to cintinue this.
But it's better to stop it.

> I would be complaining if I was sold
> a video camera that didn't record video but did suck a lot of air.

You better should open your eyes and see that a video camera is not a car.
And that you looked into the wrong manual.

> The function is called basename just like the IEEE Std 1003.1 standard
> function specified by The Open Group:

This is a C-function. Filename.basename has the same name,
and does a similar thing, but it's an OCaml-function that implements a behaviour
that is described in the OCaml-manual.

If you want the behaviour of
then use it. But you have to program in C for that.

BTW: In your examples you used shells, not C.
This again is wrong, when you compare it with C.

It's more likely to assume that a shell (which shells did you use?
different shells might also bring different results)
is intended to offer the behaviour of the C-functions,
than to assume that OCaml re-implements the shell-behaviour.

> In the examples section of that document they give these examples:
>     Input String    Output String
>     "/usr/lib"      "lib"
>     "/usr/"         "usr"

# Filename.basename "/usr/lib";;
- : string = "lib"
# Filename.basename "/usr/";;
- : string = "."
# Filename.dirname "/usr/lib";;
- : string = "/usr"
# Filename.dirname "/usr/";;
- : string = "/usr"

"/usr/" is a directory. So, Filename.dirname should give "usr".

The behaviour of OCaml's
  Filename.concat (Filename.dirname) (Filename.basename)
makes sense to me. IMHO it should be done the way OCaml does it.
And the documentation and the Implementation do not differ.
So, this is fine.
If you mean a directory, append "/", if it is a file, not use a "/" at the end.

So, the OCaml-behaviour IMHO makes sense wonderfully.