Pat Gunn (dachte) wrote,
Pat Gunn
dachte

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
closedir(SUMDIR);

for($idx=0; $idx <= $#files; $idx++)
{
parsefile($filelistLINK);
}

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
Subscribe

  • Typing in Colours

    (Cross-posted to G+, but it's more of a definitive statement of views so it goes here too) A recent instance of 「Wasted Talent」: here I'm not…

  • Loyalty

    This is meant to address three ideas: Don't blame the victim If you care for me, you'd support me unconditionally Safe zonesAnd to be a topic in…

  • What Do We Owe Each Other?

    One of the central questions in political philosophy, or perhaps one of the most intuitive initial framings, is "what do we owe each other?". I…

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments