Pat Gunn (dachte) wrote,
Pat Gunn

Orbiting Symbols

Just did some code changes to my netdiary software. Substantial code cleanups, and they're beautiful too. Here's the relevant part of the old code:

my @files = readdir(SUMDIR); # read all the filesclosedir(SUMDIR);

my @filelist = sort {$b <=> $a} @files; # Numerically sort themfit: for($idx=0; $idx <= $#filelist; $idx++)
if($filelistLINK =~ /summary/i){next fit;} # skip index
if($filelistLINK =~ /\./) {next fit;} # Skip '.' and '..'
parsefile($filelistLINK); # Actually parse a file
And the new code:

my @files = # List of files is
sort {$b <=> $a} # a numerically sorted list
grep !/^\./, # Skipping . and ..
grep !/^summary/, # and skipping the summary file
readdir(SUMDIR); # from all the files

for($idx=0; $idx <= $#files; $idx++)

For some odd reason, the way those function calls nest creates a strange image in my mind, like an ordinary program would be like


But that part is more like
---------------/ \---

And I can imagine rewriting it to pull that loop even higher, as fewer portions between statements exist and things nest further. For some reason, I'm getting thoughts that perhaps with sufficient thought, the entire program could be written going up rather than going across, although that might look ugly (both in metaphor and in the actual code). Maybe that's what LISP and similar languages would normally look like.

Tags: programming

  • Still alive

    Been feeling a bit nostalgic. Not about to return to LiveJournal - their new ownership is unfortunate, but I wanted to briefly note what's been up…

  • Unplugging LJ

    It's about time I pulled the plug on the LJ version of my blog: 1) I'm much more active on G+ than I am with general blogging. I post many times a…

  • Mutual Trust

    I don't know which should be considered more remarkable: That a cat should trust a member of a far larger and stronger species that it can't…

  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded