programming

Beautiful ideas in programming: generators and continuations

In this post, I’ll summarize what I’ve learned from an attempt to gain a deeper understanding of two important concepts in programming: Python’s generators and Scheme’s continuation. The aim is not to teach Python or Scheme programming. Rather, what I want to do is to demonstrate that generators are special cases of a much more powerful construct - continuations. Continuations allow programmers to invent new control structures, and it is the foundation upon which iterators, generators, coroutines, and many other useful constructs can be built.
Read more

Simple exercises with grep, sed and awk in org-mode

For text processing, I had never bothered to learn classic Unix tools such as sed and awk, because I can always use Python's regular expression library. The syntax of sed and awk just appeared to be too arcane to me. However, recently I realize that for many simple ad-hoc tasks, even writing a Python script is too much overhead. This motivated me to learn to use regular expressions directly in the command line.
Read more

In the 70’s, it was fashionable for intellectuals to abuse the term “grammar” to refer to any underlying principles. In one of his essays, Italo Calvino used the term “the grammar of tree” to refer to…. essentially developmental plant biology. I thought that was pretentious. But heh, in R programming, people are talking about the grammar of graphics and grammar of data manipulation again. It’s fashionable to call functions “verbs” again.
Read more

Idea: a Python dialect called Pynchon (after Thomas Pynchon). A pynchonic code is probably not very pythonic. Brevity is highly discouraged. Variable names should be all puns. In fact, Pynchon should be a concatenative language like Forth. This way, statements can be chained together into a longer and longer statement… until the entire program is one single statement.

About a month ago, I rewrote my Emacs config script in the style of literate programming. Emacs has a markup language (org-mode) that makes it easy to mix rich text with code. I did it mostly out of curiosity. At that time, I didn’t know if writing something as trivial as a config file this way was a good idea in terms of practicality. After a month of tweaking, I am now convinced that It was helpful.
Read more