newLISP Fan Club

Forum => newLISP and the O.S. => Topic started by: cormullion on May 03, 2008, 03:03:46 AM

Title: (directory) sort order
Post by: cormullion on May 03, 2008, 03:03:46 AM
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...!
Title:
Post by: Lutz on May 03, 2008, 05:53:09 AM
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'.
Title:
Post by: cormullion on May 03, 2008, 10:36:04 AM
Cool. sort is exactly the right thing here. Yet another little cross-platform gotcha eliminated...!