Why Scheme makes a good teaching language (SICP)

“In teaching our material we use a dialect of the programming language Lisp. We never formally teach the language, because we don’t have to. We just use it, and students pick it up in a few days. This is one great advantage of Lisp-like languages: They have very few ways of forming compound expressions, and almost no syntactic structure. All of the formal properties can be covered in an hour, like the rules of chess. After a short time we forget about syntactic details of the language (because there are none) and get on with the real issues — figuring out what we want to compute, how we will decompose problems into manageable parts, and how we will work on the parts. Another advantage of Lisp is that it supports (but does not enforce) more of the large-scale strategies for modular decomposition of programs than any other language we know. We can make procedural and data abstractions, we can use higher-order functions to capture common patterns of usage, we can model local state using assignment and data mutation, we can link parts of a program with streams and delayed evaluation, and we can easily implement embedded languages. All of this is embedded in an interactive environment with excellent support for incremental program design, construction, testing, and debugging. We thank all the generations of Lisp wizards, starting with John McCarthy, who have fashioned a fine tool of unprecedented power and elegance.

Scheme, the dialect of Lisp that we use, is an attempt to bring together the power and elegance of Lisp and Algol. From Lisp we take the metalinguistic power that derives from the simple syntax, the uniform representation of programs as data objects, and the garbage-collected heap-allocated data. From Algol we take lexical scoping and block structure, which are gifts from the pioneers of programming-language design who were on the Algol committee.”

Structure and Interpretation of Computer Programs, ‘1.1  The Elements of Programming

Functional programming in Python and Lisp

I’ve been trying to learn more about functional programming – specifically, looking at functional programming patterns in Python and Lisp/Scheme code. While reading about Python’s “functional” features (first-class functions, generators, list comprehensions, etc) I ran across many articles/books on functional programming in Haskell, Lisp, Scheme etc.

Years ago I had picked up a few books on Common Lisp and Scheme, but was unable to grok it due to some fundamental conceptual pieces I was missing at the time. But over the past few weeks as I have started exploring Lisp-like languages again, my mind has been blown.

The single biggest problem that I’ve had with programming languages I’ve used (C/Perl/Java/Python) is rigid and complicated syntax being forced upon me, the programmer. Constantly, this syntax is getting in the way of me clearly expressing what I want the computer to do, and is instead forcing me to contort my ideas into a form that fits into the languages’ strict and inflexible syntax rules.

The two things that have intrigued me most about Lisp are:

1) the ability to write beautiful, readable code with a simple/minimal yet highly expressive syntax (s-expressions and function application / evaluation)

2) the ability to define your own syntax using macros. If a language feature is getting in the way, you simply change it by writing macros that define customized syntax that clearly expresses concepts in a particular context / problem domain …

I am excited to explore these features more in the coming months – specifically by working with tools for Lisp/Python interaction (sharing code/data between programs written in each) … I’ll be posting writeups periodically to describe what I’ve learned.