[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Modifying DIRECTORY



  > Date: Wed, 21 April 93, 16:05 CDT
  > From: berger@cs.uchicago.edu
  >
  > The Allegro (4.1) CL version of the function DIRECTORY returns its
  > list of pathnames in modification-date order (ala ls -c). I'm using
  > code written elsewhere which uses this function, but assumes the
  > pathnames are in alphabetical order. The Allegro Manual warns against
  > messing with the package-lock system, but can anyone tell me what sort
  > of disaster I might be courting by doing the following?
  > 
  > 
  > (let ((oldirectory (symbol-function 'directory)))
  >   (excl:without-package-locks
  >    (defun DIRECTORY (&rest args)
  >      (sort
  >       (apply oldirectory args)
  >       #'string-lessp
  >       :key #'file-namestring))))

The consequence of this (in this case `disaster' is probably too
strong a word) is that if another program did a similar trick to get
the files in size order then one of the two programs will break.

A better way to do this is to shadow the symbol DIRECTORY in your
package so that any changes you make to its behaviour will only be
seen by your program.  E.g.,

  (in-package :my-package)
  (eval-when (compile load eval)
    (shadow 'directory))

  (defun directory (&rest args)
    (sort (apply #'cl:directory args) #'string-lessp
         :key #'file-namestring))