Scheme

When I was in school I wrote programs in Scheme and its variant T. I still remember that as the easiest programming language I’ve ever used. In Scheme you never waste time on pointless boilerplate. You just write code. In order to run some function on a bunch of data, a very common operation, you just write a function closure, which is trivial. Dynamic typing means that you don’t waste time writing types.

In other words, Scheme has all the advantages of today’s interpreted languages like Python and Ruby. It is more powerful in practice, because Scheme makes it very easy to manipulate and evaluate Scheme code itself, something which is not feasible in most other languages. This means that Scheme can be its own macro processor.

And of course it is possible to compile Scheme to reasonably efficient machine code–not C/C++ efficient, but not bad.

So why hasn’t Scheme caught on? It still lives in various niche environments, but it is not popular. Is it as simple as people not liking prefix notation?

When people ask me what they should do to learn to program, or more commonly these days what their teenage kids should do, I always recommend Abelson and Sussman’s book Structure and Interpretation of Computer Programs (which can now be read online). It uses Scheme. It’s the best introduction I know to what computer programming is. It’s only an introduction, of course; it doesn’t cover the issues which arise in the workplace. But I think that anybody who wants to be a programmer has to be able to master the material in that book.


Posted

in

by

Tags:

Comments

8 responses to “Scheme”

  1. tag Avatar

    An interesting note, thanks Ian.

    Like you, I think SICP an excellent introduction (and some!) to programming. I wish I’d started out on it and Scheme rather than studied it in my own time after many years of programming C-family languages. With my background, Python proved easier to “get” than Scheme, though reading SICP and using Scheme have changed my coding style in all the languages I use.

    The one problem I have with SICP is that it has grown out of date — I think it refers to some MIT dialect of Scheme: and the mere existence of multiple dialects is a warning sign for me.

    I still reach for Python first mainly because it’s more convenient. The standard libraries are comprehensive and well-documented. The module system is more sophisticated than Scheme’s, without being complex. I can access help from an interpreted session, making it easy to shape code as I go. The ease of interfacing to the OS and to C code help. And the language’s popularity means there are good books, conferences, third-party libraries, mail lists, frameworks etc.

  2. Sed Avatar

    There is also the book: Programming Languages: Application and Interpretation
    (available online at http://www.cs.brown.edu/~sk/Publications/Books/ProgLangs/2007-04-26/) which covers advanced topics like continuations, type inference, static vs dynamic languages, “infinite” structures (as found in haskell)…

    When I don’t feel too lazy I sometimes write software, in the order of tens of thousands of lines. Before reading the PLAI book I never used lisp (or scheme) because indeed the notation really looks ugly. Who wants to write all these parentheses all around, huh?

    But now I feel the need to give lisp a try. The book has an interpreter for a language with stuff like continuations. The interpreter is insanely short. There must be something in this lisp/scheme stuff that I missed.

    And the macro system is really amazing. So amazing that it’s a pity to call C #define macros.

    There is, as you say, the problem of performances. And I hate garbage collection (for surely very irrational reasons).

    So I am thinking of using lisp mostly for its macros (which allow a very quick creation of new languages without wasting time in lex/yacc/memory management issues), as an aid to write complex C programs where I usually waste a lot of time with tiny mostly automatic boring details. And when I sometimes need to change a little aspect of the program, it appears that I need to change a lot of stuff in a lot of files. (Sure I may misuse C…) Maybe by designing some nice macros in lisp can I have a system where changing a few lines lead to a radical new version of the generated C code.

    I also use to code as follows: 1 – think, 2 – apply the thinking all around. Then there is: 3 – modify the code (to add a new functionality for example). When I come to 3 I sometimes forget the 1 and so it complicates things. Maybe lisp may be used as a 1.5 step where I just encode the thinking in a few lines of code and automatically (or half-automatically) generate the wanted C code that would implement the thinking. Lisp would be used to “remember” the thinking, which often disappears in C code because of all the tiny boring little details (those details that make the difference between a program running in 1s and 1mb of RAM and another one running in 10 minutes and 200mb of RAM). (Sure, processing power is cheap today, but let’s keep being elegant a little. Pretty code matters. Especially when you don’t do it for money or
    fame.)

    There is also the smalltalk/squeak world out there. The GUI of squeak is impressive. But there again bad performances are a real barrier. There is a book “Squeak by Example” for those who want to give it a try. Smalltalk is not very popular, maybe less than lisp (source is required here), but served as a source of inspiration for many. A little time writing tiny pieces of code in squeak turns “modern” IDE like eclipse into old technology. The class browser, the completion, the debugger, the whole system… simply amazing work. Interested readers should give it a look just to see what a GUI based programming environment has to offer. Beware corporate coders: you may later on hate the bad design of your daily IDE!

  3. fche Avatar

    > […] Dynamic typing means that you don’t waste time writing types. […]

    I also find scheme exciting to program in occasionally. In my very limited experience though, a larger program will want to build some sort of typing system on top of it, for at least type assertions. Even these don’t avoid the run-time errors that a more statically typed language could have caught mechanically (via compiler or whatnot) before run-time. So it seems to me that referring to writing types as “wasted time” is too negative – it is more of an investment.

  4. Ian Lance Taylor Avatar

    tag: I view Python as being in some ways Scheme with a different syntax–although that means that it loses the macro features. And you’re right: Python clearly has more and better library support.

    sed: thanks for the book pointer. I never tried Smalltalk, or Squeak, seriously. Maybe someday.

    fche: automatic type inference techniques are pretty good these days. I agree that sometimes you do want type assertions, and I agree that static typing can catch some errors early on. But I’m not sure it’s worth it–except that it makes it much easier to compile into efficient code.

  5. tromey Avatar

    These days I’m more interested in CL than Scheme. Scheme is a bit too minimal.

    Not that I do any real hacking in either. All my real lisp code is in Emacs — which is its own bizarre, lame variant.

    I am not a big Python fan, though I do use it. When using it I’m constantly reminded of the many ways I prefer the lisp family. Macros for one, but also conciseness. And, the typical CL implementation has better performance (than CPython).

  6. eschew Avatar
    eschew

    Out of curiosity, do you have any recommendations for books that cover the sorts of issues programmers are likely to face in the workplace?

  7. Ian Lance Taylor Avatar

    tromey: I think that Scheme is the right size for a language, what it is missing is good libraries. Perhaps that it what you mean, too.

    eschew: I don’t know of any really excellent books. That said, among the books which I think are worth reading are:

    * The Mythical Man-Month, by Frederick Brooks, really old yet somehow still not out of date.

    * Code Complete, by Steve McConnell.

    * The Practice of Programming, by Kernighan and Pike.

  8. ncm Avatar

    I should mention that C++0x (C++09, if they stay on schedule, C++0xA if not) will have comprehensive support for inferred types. Most trivially,

    auto i = 3; // same as “int i = 3; ”

    auto j = 3u; // same as “unsigned j = 3; ”

    but also allowing a much more convenient notation to declare function template arguments and return types.

Leave a Reply