14
$\begingroup$

I am an undergraduate computer science student. I have completed two out four years of my degree. I have not had an interaction with any Lisp family of languages. I have strong background in C, Java, x86 assembly and Javascript (at least that's what I think).

I have read that Lisp can teach me some of the core computer science concepts. I am currently stuck in the choice between How to Design Programs (HTDP) and Structure and Interpretation of Computer Programs (SICP). I have read about 50-70 pages of HTDP and it feels quite beginner. So, I did some research on SICP and found SICP teaches Scheme. I have also read that Scheme is old and learning Racket would be a better choice. Which book should I choose?

Note: I wish to pursue further education in Computer Science possibly in researching about Programming Languages.

$\endgroup$
8
  • 5
    $\begingroup$ Just a note, you can't learn "Scheme", it is a family of languages. You must pick a flavor. Racket is an excellent Scheme variant, and comes with a lot of support for learners. $\endgroup$
    – Ben I.
    Commented Jul 30, 2022 at 20:49
  • 3
    $\begingroup$ Seibel's "Practical Common Lisp" is quite nice. $\endgroup$ Commented Jul 31, 2022 at 7:17
  • $\begingroup$ @BenI. Why do you think Scheme is a family of langauges? It's no more a family of languages than C++, with a series of not completely compatible standards. $\endgroup$
    – prosfilaes
    Commented Jul 31, 2022 at 20:17
  • $\begingroup$ @prosfilaes From Wikipedia: "This has resulted in scores of implementations,[33] most of which differ from each other so much that porting programs from one implementation to another is quite difficult, and the small size of the standard language means that writing a useful program of any great complexity in standard, portable Scheme is almost impossible.[13]". If you want to quibble with my use of the word "family" I'm happy for a better word, but there's no eponymous "scheme" that you can just install. You have to choose among pretty wildly different implementations to even get started. $\endgroup$
    – Ben I.
    Commented Aug 1, 2022 at 0:05
  • 1
    $\begingroup$ As HTDP is mentioned i point out dcic the latest work from one of the authors. Quite interesting. $\endgroup$ Commented Aug 2, 2022 at 14:35

5 Answers 5

27
$\begingroup$

How to Design Programs is a truly fantastic text. Should you choose to read it, I suspect you will be able to learn many useful things from it. However, I hesitate to recommend it as an answer to your question as-stated for two reasons:

  1. HtDP is ultimately a textbook, and it is not written to be read front to back. Rather, it is primarily intended to be used alongside a course taught by an instructor who knows how to use it most appropriately.

  2. More bluntly, HtDP is simply not a book about Lisp.

Yes, HtDP uses a programming language (or, more accurately, a family of programming languages) that happens to be a Lisp. But this is somewhat incidental, and the book can be adapted to other languages (and sometimes is in practice). Moreover, the language used by HtDP is not Racket, nor is it even Scheme—instead, HtDP uses a family of languages specifically designed for teaching, which intentionally lack many of the features that are traditionally considered the qualities that make Lisps interesting.

So what is HtDP about? True to its name, it is a book about how to design programs. It is not about how to design Lisp programs, and although it certainly does have a somewhat functional bent, its ideas are applicable to all programming languages. This is why it is often used as an introductory text. The Lisp is not the point, so if you want to learn about Lisp, HtDP is not going to leave you terribly satisfied.


Given the above, it may sound like I am strongly recommending that you read Structure and Interpretation of Computer Programs, instead, and that is not entirely untrue. Unlike HtDP, SICP is not an introductory text (as much as people sometimes seem to pretend otherwise), but it’s also not really about Lisp, either. Rather, SICP covers some of the foundational ideas in the field of programming languages, and it explores these via simple interpreters written in Scheme. Many of the ideas in SICP are definitely “Lispy” in some sense, and you say you’re interested in perhaps pursuing the field of programming languages, in which case I suspect you will find SICP quite edifying. On the other hand, I personally think many of its ideas are presented better elsewhere (though many would disagree, so YMMV).

Ultimately, the question comes down to what you really want to learn about. Here are a few possibilities:

  • If you want to learn about writing programs in Lisp or about functional programming more generally, I recommend reading The Racket Guide. The Racket Guide does not exactly present itself as a book, but it is structured like one, and it provides a very thorough introduction to programming in a full-featured Lisp that covers everything from the bare basics to compile-time metaprogramming to higher-order contracts. The Racket Guide is a wonderful resource that will give you everything you need to start writing real Lisp programs (and then some).

  • If you want to explore the foundations of programming languages using a Lisp as a vehicle, then I recommend Programming Languages: Application and Interpretation by Shriram Krishnamurthi. PLAI covers much of the same content as SICP, but it does so in a more precise and less handwavy way, and it also covers more topics, such as garbage collection.

  • If you want to learn specifically how to implement a simple Lisp, then I actually think it’s quite possibly more illustrative to do that in a language that isn’t a Lisp. Write You A Scheme uses Haskell as its implementation language of choice, which I think provides a particularly lucid grounding for the ideas it introduces.

Ultimately, all of the things I’ve mentioned here—including both HtDP and SICP—are good reading, so I wouldn’t worry too much about which one you pick. It would certainly be counterproductive to feel overwhelmed by choice and not end up reading any of them, so don’t get stuck in analysis paralysis. But personally, based on the contents of your question, I think The Racket Guide and PLAI would both be great choices to help you get started on your journey into Lisp and programming languages.

(Disclaimer: I am a regular contributor to Racket and am currently employed working on GHC, the Haskell compiler. I like to think my suggestions are relatively unbiased in spite of my personal interests, but then, we all do. :))

$\endgroup$
4
  • 1
    $\begingroup$ Is there a way to escape DrRacket IDE hell? Personally, I don't like IDEs and I would appreciate if you could tell there is command line racket interpreter available for Unix based systems? $\endgroup$ Commented Jul 31, 2022 at 17:42
  • 3
    $\begingroup$ @TaimoorZaeem You are certainly under no obligation to use DrRacket. The racket command-like executable drops you into a REPL if given no arguments, and there’s also a racket-mode for emacs. $\endgroup$ Commented Jul 31, 2022 at 17:44
  • 1
    $\begingroup$ WYAS is perhaps not the best choice, since Haskell is very different from both Scheme and the languages OP claims to know. OP would have to first learn Haskell to derive the greatest benefit from WYAS. $\endgroup$ Commented Aug 1, 2022 at 20:31
  • 1
    $\begingroup$ @TaimoorZaeem there is also good Vim support available. See the racket docs on editors $\endgroup$ Commented Oct 22, 2022 at 21:50
7
$\begingroup$

As someone points out in the comments, Racket is a Scheme implementation. But I wouldn't worry about which Lisp variant you learn at first, not even whether it's a Lisp-2 (Lisp) or Lisp-1 (Scheme); the things you need to learn initially will be taught pretty much as well in any variant.

The book I recommend you start with is The Little Schemer by Daniel Friedman.

The first few chapters are essentially simple exercises that will introduce you to the basic idioms used by many functional programming languages that imperative programmers are generally not used to, including manipulation and use of singly-linked lists, iteration via recursion (rather than loops), functions as first-class objects, lambdas (anonymous functions), and so on. The book's question-and-answer format helps you practice with these idioms; this is key because easy and fluent use of them is absolutely essential in most functional programming languages, even ones as different from Lisp as Haskell or ML.

The later chapters of the book go deeper into what you might call the very heart of functional programming, covering both things less discussed, such as currying, and some fairly complex things, such as the applicative-order Y combinator. The book ends with the following; if you have difficulty wrapping your mind around it, well, that's why you need to do the exercises in the book:

(define Y
  (lambda (le)
    ((lambda (f) (f f))
     (lambda (f)
       (le (lambda (x) ((f f) x)))))))

From the start you may find that short (less than 200 page) book looks overly simple; don't be fooled. Depending on your previous experience, some parts may indeed actually be simple for you, but if so, you'll get through them quickly and waste little time. But if there are any questions that you don't fully understand, don't skip them; go back and contemplate them and do your own exercises based on them until you are confident you have mastered them.

The book can easily be worked through with pen and paper, and that's the way I recommend you do it. However, if you feel you want to use an interpreter, almost any Lisp or Scheme interpreter will do, though you may have to look up a few details for your particular version of Lisp or Scheme that differ from the book. The book does have some footnotes giving Lisp equivalents of the Scheme functions/macros they use, where the Lisp functions/macros differ.

$\endgroup$
6
$\begingroup$

The problem with learning any of the Lisp family of languages after learning several others is that Lisp and its progeny use a different paradigm. Changing paradigms implies changing the way you think. It isn't about syntax, but about a mental model of the nature of computation.

There is nothing naive about SICP, but you need to get beyond the first few pages. Once you have internalized the thought process, you can move to other functional languages, just as you can move from Java to Python, say.

The big difference between pure functional languages and those you already know is the replacement of "state" represented by variables with "expressions".

Racket and Scheme share many things, including an abstract syntax. But the most important thing they share is the computing model; the paradigm and that will be the biggest hurddle.

But, either of those books should be fine for a first look at FP. The authors are among the finest around and all have a very deep knowledge of their respective topics.

$\endgroup$
5
  • 3
    $\begingroup$ While I have no disagreement with the general outline of this answer, I wonder about phrasing it using terms like "problem" and "hurdle". Learning a new programming paradigm is a wonderful opportunity and can be very enjoyable; it widens the mind of a CS student and prepares it for further widening. At least that is how I perceived working with LISP (specifically, Common LISP) when I learned it in the 1980s. My university mandated that CS students learn either LISP or Prolog to make sure they had a grasp on programming languages beyond procedural ones. $\endgroup$
    – njuffa
    Commented Jul 31, 2022 at 3:24
  • 2
    $\begingroup$ "The problem with learning any of the Lisp family of languages after learning several others is that Lisp and its progeny use a different paradigm." – Although the OP says they have a strong background in JavaScript, which is essentially Scheme with a thin veneer of NewtonScript, Act-1, and Self. At least, that was my epiphany. I tried learning JavaScript multiple times, but it only clicked for me when I realized that I should ignore everything I ever learned about JavaScript and simply think of it as Scheme with dictionaries instead of lists as the ubiquitous data structure. $\endgroup$ Commented Jul 31, 2022 at 13:47
  • $\begingroup$ @JörgWMittag To expand on what you say, the "paradigm" of the Lisp family is that everything is a reference to first-class objects. This exists in the popular scripting languages: JavaScript, Python, PHP (except that arrays are copy-on-write). That hurdle is often the biggest when going from traditional languages to Lisp, and he's achieved it if he understands JS. $\endgroup$
    – Barmar
    Commented Jul 31, 2022 at 18:54
  • $\begingroup$ Best class in which I ever enrolled was called, "Comparative Programming Languages." The list of languages included Lisp, Pascal, SNOBOL4, Smalltalk, Prolog, and one or two others. (It was forty years ago, my memory is dim.) The primary focus was on how different languages support different ways of thinking about a problem. Secondary attention was paid to the tradeoff between benefits of certain language features (e.g., Lisp's lexical closures) vs. the cost of implementing and/or using those features. $\endgroup$ Commented Aug 6, 2022 at 14:32
  • $\begingroup$ @SolomonSlow, such a course is best if it focuses on "principles of programming languages" rather than "examples of programming languages". Your course may have been more in the first category. $\endgroup$
    – Buffy
    Commented Aug 6, 2022 at 14:35
4
$\begingroup$

The best book to get into Lisp is Peter Norvig's PAIP - it showcases the core Lisp multi-paradigm approach and also some unique Lisp features that make it suitable for solving problems dealing with knowledge manipulation.

The other great book for those who, like you, have significant conventional programming experience is Peter Seibel's Practical Common Lisp which introduces Lisp in the familiar context of those language's approaches.

Finally, for those who have very little programming experience or for kids, Conrad Barski's Land of Lisp may be a good accessible and light-hearted introductory book.

$\endgroup$
1
$\begingroup$

Frame challenge, don't start with a book. Start with Problem 1 on Project Euler (spoiler, Problem 1 is just Fizz Buzz) and Google/Stack Overflow/language documentation and just write some code. Your first code will be terrible Lisp since your brain will still want to work procedurally and that's OK, imo actually experiencing this is the best way to really know how Lisp is different from procedural code.

I think Project Euler is particularly good for this because a) a lot of the questions have very elegant recursive solutions so the reward for writing idiomatic Lisp is high, and b) there are usually several Lisp solutions posted in the forums for easy problems so you can see how other people solved the same problem. (Plus you get a bonus of seeing how people solved it in other languages.)

Then you can go read a book and build an academic understanding on top of your intuitive understanding.

$\endgroup$
1
  • 1
    $\begingroup$ The Dreyfus model of learning indicates that novices learn best through starting out by being told exactly what to do, moving on to minor variants of that, and only slowly generalising to rules, guidelines, and so on. I've found this to be true in my experience as well. That's why I recommend The Little Schemer first; it will directly teach you the idioms rather than leaving you stumbling around trying to figure out what they are. The Project Euler problems would be a great exercise after learning the basic patterns of problem solving in Lisp. $\endgroup$
    – cjs
    Commented Aug 7, 2022 at 12:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.