[comp.lang.misc] trivial portability

gumby@Gang-of-Four.Stanford.EDU (David Vinayak Wallace) (03/23/90)

   Date: 22 Mar 90 18:55:53 GMT
   From: adrian@mti.mti.com (Adrian McCarthy)

   Exercise for the reader:  write a *portable* program in any language which
   takes a file name as its parameter and returns the modification or creation
   date and time of that file.  Don't use any conditional compilation.

Took longer to trim your message above than it took me to write the
code below (in common lisp):

(defun demo ()
  (format "~&Enter pathname to examine: ")
  (let ((pathname (pathname (readline))))
    (multiple-value-bind (second minute hour day month year)
			 (decode-universal-time (file-write-date pathname))
       (format "The file was written by ~a; on ~D-~D-~D at ~D:~D:~D"
	       (file-author pathname) day month year hour minute second))))

skef@skef.slisp.cs.cmu.edu (Skef Wholey) (03/23/90)

    Date: 22 Mar 90 21:47:20 GMT
    From: gumby@Gang-of-Four.Stanford.EDU (David Vinayak Wallace)

       Date: 22 Mar 90 18:55:53 GMT
       From: adrian@mti.mti.com (Adrian McCarthy)

       Exercise for the reader:  write a *portable* program in any language which
       takes a file name as its parameter and returns the modification or creation
       date and time of that file.  Don't use any conditional compilation.

    Took longer to trim your message above than it took me to write the
    code below (in common lisp):

    (defun demo ()
      (format "~&Enter pathname to examine: ")
      (let ((pathname (pathname (readline))))
	(multiple-value-bind (second minute hour day month year)
			     (decode-universal-time (file-write-date pathname))
	   (format "The file was written by ~a; on ~D-~D-~D at ~D:~D:~D"
		   (file-author pathname) day month year hour minute second))))

Wow, you sure can write buggy code quickly!  I don't mean to be pedantic
or snotty or anything -- I just think it's kind of funny that in the
six-line body you've got three bugs.  Both calls to Format need a stream
argument, and the Common Lisp function is called Read-Line, not
Readline.  But, with these things fixed, it does indeed do the job.  It
was kind of neat to cut the code from rn running in an xterm and paste
it right into my Lisp editor.  I bet I got the error messages even
faster than you generated the bugs!

Also, you're not quite following the spec as written (the file name should
be an argument), but I would be picking nits it I picked on that.

(For a good time, look up "Teenage Mutant Ninja Turtles" (or even
"Turtles, Teenage Mutant Ninja") in the index to CLtL 2nd edition.  Also
look at the entry for "hyperspace."  You must admit the index is an
improvement over the first edition....)

--Skef