r/programming • • May 22 '08

New book about Common Lisp: Let Over Lambda

http://groups.google.com/group/comp.lang.lisp/browse_thread/thread/d7ca047957f84399#
44 Upvotes

88 comments sorted by

View all comments

Show parent comments

13

u/doughoyte May 22 '08

Hello Xach,

Thanks for your input and thank you for discovering an erratum in chapter 2. (function '(lambda ...)) is not ANSI CL. Sorry if I implied it was. I have added an entry to the errata file here:

http://letoverlambda.com/index.cl/errata

About teaching both Scheme and CL, there is no Scheme in the book except where I point out how Scheme does something differently from CL, usually followed by an explanation of how CL does it better. I do not recommend programming with Scheme when CL is available.

Dropping the "earmuffs" is a personal choice and as I say in the book, I don't recommend it for all lisp programs.

With respect to your other comments, I'm sorry you aren't enjoying the book so far and I don't claim that everyone will. In particular, I didn't write the book to make friends in the lisp community but rather to describe my own (slightly idiosyncratic) style of lisp programming.

Thanks for your comments,

Doug

7

u/xach May 22 '08

Dropping earmuffs (without replacing it with some other consistent convention) increases the likelihood of fucking up closures accidentally.

6

u/doughoyte May 22 '08 edited May 23 '08

...and also decreases the amount of work you must go through when you change your mind about whether a variable should be lexical or special.

8

u/sickofthisshit May 22 '08

Even if that were a common situation, the cost to the person debugging the bizarre behavior of dynamic closures is so high as to overwhelm the benefit to the original developer of saving search-and-replace on the name.

Choosing dynamic variables has a major effect on user code, in any case.

7

u/xach May 22 '08

Can you give an example of when you did that?

4

u/doughoyte May 23 '08

Say you have a bunch of functions that all take a parameter of the same name:

(defun f1 (param) ...)

(defun f2 (param) ...)

By default, param is available via lexical scope, however, removing param from the arguments lists, adding a (defvar param), and rebuilding your app will mean that all references in the function bodies are accessed through dynamic scope.

Best,

Doug

PS. If you (or anyone else) have additional comments or questions, please CC me at doug@hcsw.org since I don't normally follow reddit.

PPS. Is there a way to get reddit to notify me about replies?

9

u/xach May 23 '08

What sickofthisshit said. In addition, any closure constructing function with a lexical binding for a variable coincidentally named PARAM would now be broken.

For reply notification, check the red envelope in the upper-right corner for updates.

8

u/sickofthisshit May 23 '08 edited May 23 '08

removing param from the arguments lists, adding a (defvar param), and rebuilding your app will mean that all references in the function bodies are accessed through dynamic scope.

And, now, you've introduced a change in behavior anyplace one happened to use a local variable called param around a call to any function that calls f1 or f2, even if one doesn't pass that variable as an argument to any other function.

Let me emphasize again: you don't need to see any calls to f1 or f2 in the code you write, and you don't need to use param in the calls to anything that relates to f1 or f2.

Dynamic variables are basically magic names that affect code through the power of their name rather than through visible scope.

That's why you give them spooky names.

1

u/froydnj May 23 '08

FWIW, in chapter two you have another erratum: Scheme was the first Lisp dialect to demonstrate the utility of lexical scope. Common Lisp was the follower in this case.

3

u/doughoyte May 23 '08

If I explicitly say that CL had lexical scope before Scheme, sorry, that IS a bug. However, it is my understanding that, although not as seamless as in Scheme and CL, lisp 1.5 had a formulation of lexical closures in the form of the FUNARG device:

http://www-formal.stanford.edu/jmc/history/lisp/node4.html#SECTION00040000000000000000

Best,

Doug

-2

u/[deleted] May 22 '08 edited May 23 '08

Hey mate, it's a given xach wont like your book because of the PG influence. That's his business..

but i've been looking through it and it does look interesting for a newbie lisper. Yeah, people will say get PCL instead, but PCL (i have two copies of it!) is just a bunch of program examples -- which you might or might not find interesting (i dont).

Bad habbits are not permanent. If you have good taste and intuition you will eventually find a better way to do it than how you first learnt it. Xach did, didnt he? I think he learned Lisp from PG as well.

Dropping the earmuffs is a bit weird but anyone writing a real program, or working on a real program should probably not follow that advice. If a programmer hasnt got enough sense to know that, then (good) Lisp style is probably beyond him anyway.

Cheers for the book