[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))
  ;;    )
  ;;   )

Hi Jeff,

I'm also a bit annoyed by the persistence with which Allegro protects
the built-in CL symbols - I can't even locally override CL fundefs
within an FLET/LABELS without having a flood of warnings thrown at me.

In your case, however, you might want to consider the ADVICE util to
modify the DIRECTORY function:

   USER(11): (directory ".")
   (#p"./errno.o" #p"./top-level-wrapper.fasl" #p"./top-level-wrapper.lisp.~1~"
    #p"./TAGLIST.~31~" #p"./TAGS.~31~" #p"./TAGLIST.~32~" #p"./COPMA-II.lisp"
    #p"./top-level-wrapper.lisp" #p"./TAGS.~32~" #p"./TAGLIST" ...)

Unsorted, default listing returned.

   USER(12): (excl:defadvice directory :around
	      (sort :do-it #'string-lessp :key #'file-namestring))
   DIRECTORY

   USER(13): (directory ".")
   (#p"./bup-4-4-92" #p"./COPMA-II.lisp" #p"./enlib" #p"./errno.o" #p"./example" #p"./junk"
    #p"./kernel" #p"./Makefile" #p"./manual-make" #p"./networking" ...)
   USER(14): 

Sorted, as intended.

Cheers,
Eyvind.


~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
  Eyvind Ness         Internet: Eyvind.Ness@HRP.No
  Research Scientist  Voicenet: +47 69 183100 ext. 275
  CRS Division        Faxnet:   +47 69 187109
  OECD HRP            Papernet: PO Box 173, N-1751 Halden, Norway

~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

 -Applicants must also have extensive knowledge of Unix, although they
should have sufficiently good programming taste to not consider this an
achievement.

        MIT AI Lab job ad in Comm. of the ACM, vol. 35, no. 6, June 1992, pp. 160