(directory) sort order

Machine-specific discussion
Unix, Linux, OS X, OS/2, Windows, ..?
Locked
cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

(directory) sort order

Post by cormullion »

I noticed today that BSD and MacOS X sort the results of a newLISP (directory) call differently when there are numbers involved...

In BSD:

("." ".." "10atom.lsp" "20cache.lsp" "default-plugin.lsp" "01debug.lsp")

In MacOS X:

("." ".." "01debug.lsp" "10atom.lsp" "20cache.lsp" "default-plugin.lsp")

I don't understand the BSD order...? Luckily, (sort) to the rescue...!

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

The order in which (directory) returns the entries is the same as doing an 'ls -f' in a shell window.

Only on Mac OS X this a (natural) alphabetical sort order. On other UNIX this is the order in which they appear in the OSs internal directory hash table, which depends on the hash function used and the sequence in which entries are created.

The only way to get a platform independent sort-order is to sort the list with 'sort'.

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

Cool. sort is exactly the right thing here. Yet another little cross-platform gotcha eliminated...!

Locked