Functional programming
Going further with JavaScript and the DOM
One of the main things that really blows programmers’ minds when they really see the power of it is a topic called ‘closures’ or ‘lambda functions’ or ‘anonymous subroutines’.
I decided to edit the previous post’s code to use closures, to get the hang of this technique in JavaScript. It makes your code a lot more flexible as I think the simple example below demonstrates.
For the code, look after the jump…
How I write Perl
When I write Perl, on my own, it looks like the following. This is Perl written in the “functional” style I advocate.
The code takes a listing of simple definitions:
tree noun something organic with leaves
and turns it into LaTeX Beamer–class slide markup.
\frame{
\frametitle{tree }
\begin{itemize}
\item tree
\pause
\item noun
\pause
\item
something organic with leaves
\end{itemize}
}
When the Beamer LaTeX code is complied with pdflatex it produces a slide show.
You can see how something like this is handy for someone studying their GRE Vocabulary builder. Code after the jump.
Benefits of "Functional Perl": ease of modification
In an earlier post I provided code demonstrating my “functional” Perl idiom. The purpose of that code was to take a very simply formatted text file and to turn it into LaTeX Beamer formatting.
Well, recently I found the application iFlipr. In addition to being a site where you can upload flash cards, it also has an iTouch / iPhone version so that you can review when you’re in the bus, in a waiting room, etc.
So, I needed some code to transform my generic data set into–not LaTex–but iFlipr format. With but the most trivial of changes, I was able to accomplish this.