Once upon a time, I read this post on iterators. Yesterday, a solution struck me for absolutely no reason.
How do you stop internal iteration without non-local returns? Channels!
Showing posts with label fp. Show all posts
Showing posts with label fp. Show all posts
Friday, July 12, 2013
Tuesday, July 17, 2012
find: arguments are not actually one big expression
I first learned about find somewhere around 12 years ago, so the documentation today might contradict me, but I’ve been carrying around in my head this false notion: that flags like
They don’t, in fact, participate. find accepts them with
I was intending to do CRLF→LF translations only on text files, and the extension-matching came after the
The correct way to write the command is actually:
-print0 participate in the conditions as a true value while they update a flag that sets the eventual output format.They don’t, in fact, participate. find accepts them with
-print0 -a «expr» syntax just to mess with you, and outputs the filename as soon as it sees the -print0 option. That means these two commands are equivalent:And in fact, if you offer multiplefind . -print0 -a «expr»
find . -print0
-print options, you'll get each filename printed out multiple times.I was intending to do CRLF→LF translations only on text files, and the extension-matching came after the
-print0. Since find emitted no warning, I only noticed the damage when I deployed the website and looked at Firefox valiantly trying to make sense of all the broken images.The correct way to write the command is actually:
find . «expr» -print0
This triggers the -print0 “option” only once the complete expression has matched. And suppresses the regular/default -print, of course.
Monday, February 28, 2011
Variable scope, require, and use
I ran into some interesting problems in Perl, which invoked more learning around the require/use mechanisms and how constants are interpreted. In this post, I'll lay out some general terms about variable scoping, such as lexical scope, dynamic scope, the differences between them, and how they all interact in Perl. And then I'll cover require and use with that foundation in place.
If you've been wondering about lexicals or closures, this is your post. I've tried to lay things out more or less from basic principles, despite the verbosity of the approach, because this has taken me years to understand. I started programming with Perl in 2000 and still learned a bit more about it today. Yes, it's 2011 now. Hopefully, you can read this and get it in less time.
If you've been wondering about lexicals or closures, this is your post. I've tried to lay things out more or less from basic principles, despite the verbosity of the approach, because this has taken me years to understand. I started programming with Perl in 2000 and still learned a bit more about it today. Yes, it's 2011 now. Hopefully, you can read this and get it in less time.
Sunday, August 1, 2010
Functional vs. Object Oriented
By the time I reached my first programming job, I had learned a number of languages well enough to program in, and thought of myself as a pretty good programmer. Then I met Brian, who frequently talked about Lisp, but had trouble articulating the advantages himself. (This turns out to be a common problem.) He introduced me to the SICP videos, and I found Slava Akhmechet's "The Nature of Lisp" essay on defmacro.org at about the same time. Certain things about Perl and Javascript suddenly made sense, filling me with newfound wonder.
What I thought I knew about OOP as taught in college—Encapsulation, Polymorphism, and Inheritance—seemed like a sham.
What I thought I knew about OOP as taught in college—Encapsulation, Polymorphism, and Inheritance—seemed like a sham.
Subscribe to:
Posts (Atom)