(directory) sort order

Started by cormullion, May 03, 2008, 03:03:46 AM

Previous topic - Next topic

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

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

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