197 points · by Tomte · 2y ago · 128 comments
I've been trying to work through The Little Schemer myself lately in the same vein as the poster. It's tough going, honestly, but so far I think it's been worth it.
The biggest thing with the older ones is the lack of assumption of Internet, so the book will refer to itself instead of referring to online/other documentation.
I've learned things reading a "Missing Manual" for an operating system that is 15 years out of date that still work today.
I also miss this aspect of old books. They were more self-contained.
Compare to far too much online documentation. This is what I've frequently run into. I want to learn about some particular subject, so I find a site that has an introduction or tutorial on that. The document is even book-like in the sense that it is organized as pages, and at the bottom of each page there are "next" and "previous" links.
But there is a sidebar on each page, with lists of related material and some of that sounds like material I'm going to need to know at some point. But there is no indication if it is material that I'm going to come across later if I just keep following the "next" links or it is something beyond the scope of the current document that I'll need to bookmark now to come back to later.
But I feel much of the documentation/reference around things from 2010 is both late enough that it wasn't printed, and old enough that what was online has failed or faded away.
gopher://hoi.st
It has virtual machines implemented in awk, some generic awk library and a good 'phlog' to read great posts on unix, minimalism and several tools and games. The freecell game it's a easy example.
I have used it to teach scheme/lisp to people who would never learn "programming". It's just that good.
"You may well be wondering by this stage why the computer isn't taking any notice of all this rubbish you've typed in. The reason is not that it's already noticed it's rubbish, but simply that it hasn't looked yet. It won't take any notice until you press what is just about the most important key on the keyboard, the one marked ENTER (on the right-hand side, one row up)."
http://jupiter-ace.co.uk/downloads/JA-Manual-First-Edition-[...
I was fortunate enough to have had a Xerox 1108 Lisp Machine purchased for me in 1982. I loved it with InterLisp-D but a few years later I started running it in Common Lisp mode, and the 1.5 megabytes of RAM in my 1108 was not really adequate.
In any case, the Medley developers make it easy to try Medley so give it a try.
Medley is written is largely written in Interlisp (and a bit of Common Lisp), including its UI. Interlisp (originally as BBN Lisp) was originally developed as an integrated development environment with complete source management (similar what Smalltalk later did). In the 70s it was then moved to the metal on early workstations (again, similar what Smalltalk did) -> it was its own OS. It does memory management, networking, graphics, all in Interlisp, ... Its purpose was to be a development environment for Lisp (here Interlisp).
Mathematica's purpose is to be an integrated tool in the mathematics domains, including applied mathematics in physics, chemistry, visualization, biology, ...
The nearest system to Interlisp-D is/was Smalltalk 80.
Do you use both, rather than one predominantly?
EDIT: the reason why I usually use a LispWorks console save instead of SBCL is obscure: I often ingest very large text files, and the last time I checked a few years ago, LW was faster at this than SBCL. For regular CL hacking, SBCL is fine.
In [1]: my_list = [1, 2, 3]
...: my_other_list = [4, 5, 6]
...: final_list = [str(i) for i in my_list ++ my_other_list] # whoops a syntax error!
...:
...: "".join(final_list)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[1], line 3
1 my_list = [1, 2, 3]
2 my_other_list = [4, 5, 6]
----> 3 final_list = [str(i) for i in my_list ++ my_other_list] # whoops a syntax error!
5 "".join(final_list)
TypeError: bad operand type for unary +: 'list'
In [2]: my_list = [1, 2, 3]
...: my_other_list = [4, 5, 6]
...: final_list = [str(i) for i in my_list + my_other_list]
...:
...: "".join(final_list)
Out[2]: '123456'
All the CL REPLs I've tried only allowing getting back one line at a time, which feels tedious to execute in order. I feel like I'm fundamentally missing something about iterative development in Common Lisp and it's blocking me from learning the language.SBCL doesn't have anything that I'm aware off, neither does CCL.
I've seen mentioned of wrapping SBCL in a readline wrapper. There's a program that essentially gives readline behavior to anything that reads stdin, a readline interface. It may be name something clever like "readline", I've forgotten. I've never used it.
The terminal experience is weak on those Lisps simply because of the dominance emacs has in this space. Wrap SBCL or CCL in Slime and you get readline and more. There's simply little demand for a more functional CLI when the emacs/slime combo is so powerful and useful.
The burden for Slime and emacs (for this use case) is actually quite low. Both are pretty easy to install, modern emacs out of the box works with simple mouse gestures and arrow keys, so you don't need to be an emacs wonk to use it. And Slime has its own dropdown menu for most tasks.
Readline in CLISP is useful, it makes CLISP orders of magnitude more useable than raw SBCL. Cutting and pasting S-Exprs is just not a great experience for routine work, IMHO. One advantage of readline over the emacs buffers is that when you up-arrow, you get the form. In the buffer, if you up-arrow you go up one line. Mildly annoying when your last form spat out a 1000 lines. (That's why you search instead, but, nit noted.) With readline your REPL experience is more like the shells.
And that may all work with the readline wrapper, but the wrapper may well not be aware of S-exprs, so if you enter a multi line expression and up-arrow you may get just the last line of your last expression. Kind of worst of both world. But, I'm just supposing here, I've not used it.
I'm quite content with CLISP (which does not have a lot of modern activity on it), I just wish I could get it with SSL. This seems to be some grand challenge I have not found a top-of-first-page "SSL in Clisp" solution for on google.
Anyway, enough rambling.
Install emacs and slime.
And/or run your repl inside emacs and you’ll have your whole history available right there.
python's built-in repl also lacks the desired feature, and it's kind of a pain in the ass, but the ^o keybinding can go some distance to compensating for it; when you use ↑ or ^r to get back to a desired line in history that begins a multiline block, after editing it, type ^o instead of enter, and the next line will appear below. works in bash too, and it's super common in my experience to want to run multiple historical commands in sequence instead of just one
jupyter notebook is maybe a better alternative to the emacs feature. darius bacon's halp provides a sort of notebook-like feature in emacs
My goal isn't really to get "IPythonButForCommonLisp", but to iteratively build up programs so I can quickly learn syntax. I'm going to go with the Slimv suggestion the next chance I get and see if that solves it. Instead of working in revisioned code, I'll probably just work in `Untitled.lisp` until I get the hang of things.
They will normally let you write as many lines as needed for an expression and then let you go back and edit the whole thing.
You never type into the REPL but include comment sections across your programs where you write code as it's intended to be used/executed and then use key bindings to highlight/run in your REPL.
This allows you write several lines and highlight them in order to run them.
(let* ((my-list '(1 2 3))
(my-other-list '(4 5 6))
(final-list (concatenate 'list my-list my-other-list)))
(whatever-cl-calls-join final-list ""))
This is a single Lisp form evaluated at the REPL that you could get back and edit as necessary. It's been a decade or so haha but that's the ideaI've looked it up and Common Lisp doesn't seem to provide such an option. Seems like an odd restriction. Oh, and the difference between LET, LET* and LETREC is another weird break from convention.
the exception is basic, where you could defint i or dim x(128) at any point, but it would be an understatement to say that basic's conventions were not widely emulated by other languages
I'm not sure what you mean about the difference between LET and LET* (the latter simply lets subsequent variable declarations refer to previously declared variables in the same block), and LETREC is not a builtin part of Common Lisp.
ANSI C89 requires that variable declarations only occur at the beginning of the scope.
That was long before C99; the project started around the middle 1980s, I think.
CLISP might benefit from being updated to C99, with all the files renamed to .c, and varbrace eliminated, but I don't think anyone's gotten around to it.
(let (foo bar baz)
(setf foo 2)
(other-code)
(setf bar (expt foo 2))
(more-code)
(setf baz 5))if you read documents from that era, the code that they write is wildly alien, because present day programming wasn't invented yet. things that you take for granted just didn't exist. common lisp and to a lesser extent scheme carry all that baggage for backwards compatibility.
so when lisp came out, it didn't have LET, and LET didn't appear until mid 70s. and it was added as a convenience macro for ((lambda (VAR1 VAR2 ...) ...) FORM1 FORM2 ...), which is how people did dynamic binding (also called lambda-binding) for a decade prior. evolution of lisp claims that LET came from lisp machine lisp, but people were independently inventing it all over the place, as a custom macro. depending on how your lambdas were evaluated or how your LET macro was written, you're not just assigning VARs simultaneously, you might not even have a guarantee of the order of evaluation of FORMs. but it got its job done, which is according to revised scheme manual "allowing the forms for the quantities to appear textually adjacent to their corresponding variables". this was a novel convenience at some point!
LET* was invented after LET as a convenience for LET, because sequential binding was even more convenient than binding in general. it would've made sense to then make LET* the "default" of some sort, but the subtle distinction stuck for reasons of legacy code, writing conventions, acquired preferences, and then it got crystalized and preserved for posterity in the common lisp standard.
Other Algol-like languages including Algol itself also separate declarations and statements: Pascal, Modula, Ada, ...
In C90, you can have variables anywhere, but they must be wrapped in a compound statement. This has a number of advantages:
1. You can repeat variables:
{
int yes = 1;
setsockopt(fd, SOL_SOCKET, SO_WHATEVER, &yes);
}
{
int yes = 1;
setsockopt(fd, SOL_SOCKET, SO_OTHER, &yes);
}
2. You can move code around more easily, and move these sub-blocks into their own functions more easily, since they follow "declaration close to use".3. You control the end of the scope of the variables, not only the beginning. You know that after each of the above two closing braces, the yes variable is no longer in scope. (If there is a yes variable in scope, it must be coming from a parent scope; it is not "leaking" sideways.)
4. If you write a goto which goes around these encapsulated scopes, that goto does not jump into a region where the variable is uninitialized. Compare:
void fn()
{
goto end;
{
int x = 42;
}
end: ;
// x is not in scope here, OK
}
void fn()
{
goto end;
int x = 42;
end: ;
// x is in scope here, but not initialized!
}
For these reasons, I avoid mixing declarations and statements in C programming; the separation is a very good idea. It's enforced in Ada, where it is rationalized with safety arguments. Mixing declarations and statements encourages bugs. It lets you hack dubious solutions into the program without having to think about how its structure could be improved to do it cleanly.In Common Lisp and similar dialects, you can mix imperative code with variable definitions by using progn.
(let ((x (get-x-object)
(y (progn (perform-side-effect)
(get-y-object)))
(z (get-z-object)))
...)
On a small number of occasions, I've done the above in C, using the comma operator, to avoid mixed declarations and statements: int x = get_x();
int y = (perform_side_effect(), get_y());
It's a little dirty but not as dirty as mixed declarations and statements.Also note that there is no need for mixed declarations and statements, if your code is functional! In any of your code that emphasizes functional programming, you should not run into a need for this, because the entire purpose of the feature is to be able to stick a side effect between variable definitions, which has to be sequenced there.
The Scheme language has the feature of defining variables anywhere. You can use the define form in any scope, like inside a function:
(define (fun arg)
(define x 0)
(define y 1)
...)
How this works is that Scheme implementations perform a code walk which transforms these defines into nested let forms. Each sequential body of expressions has to be scanned for the presence of define and treated this way.It's pretty ugly; you end up with what looks like a self-contained form (define x 0) that is frobbing the surrounding lexical scope, such that another form not enclosed in it depends on its definition of x.
In Common Lisp and related dialects, anything that starts with "(def" is understood to be for top-level definitions only, which work by performing a run-time side effect when they are evaluated. (And so their effect is visible to later forms not due to lexical scope but due to the chronological order of execution.)
There is a strong metaprogramming advantage in having rigid variable binding forms like let. Because let has all the variables in one place, it is easy to interpret and compile. This is one of the things that helps a Lisp-in-Lisp metacircular evaluator be very short. If you have variables defined anywhere, it means that every form that contains statement-like forms must be scanned for those definitions. They are not in a fixed place in the AST: (let vars form ...). That is one big reason why if you implement Scheme's define, you want that to be expanded early, so that everything downstream just sees nice nested lets.
(let ((my-list '(1 2 3))
(my-other-list '(4 5 6)))
(map 'String #'write-to-string
(append my-list my-other-lisp)))
No need for 'join the list to an empty string to convert it' shenanigans. (let ((my-list '(1 2 3))
(my-other-list '(4 5 6)))
(format nil "~{~A~}"
(append my-list my-other-list)))• With Emacs + SLIME, we can type C-M-x (evaluate current top-level form) or C-x C-e (evaluate the expression before the cursor).
• With Vim + Slimv, it is ,e and ,d respectively.
• Yet another popular option is Vim + Vlime in which case the key sequences are \ss and \st instead.
I have written two guides to explain how to create such a development environment from scratch and get started with such a setup:
• https://github.com/susam/emacs4cl
• https://susam.net/lisp-in-vim.html
There are commercial implementation + IDEs too which according to many people provide even better integrated development experience. The most popular among them is perhaps LispWorks. I use Emacs + SLIME myself.
For anyone else that knows Vim but can't seem to get a good CL environment going, read https://susam.net/lisp-in-vim.html
Lisp development in a terminal, without an editor, is not so helpful.
The R in REPL stands for READ, which is a Lisp function, which reads an expression and returns data.
I ended up getting rid of most of them a while back, since I carried them with me from move to move. Now that I'm in a place that I'll be in for a long time, I really miss these books.
The coolest one I saw, but never picked up, was a book entirely dedicated to creating a chess engine. It was published years ago at the time I saw it (seen 2013, published in 1980?), but I doubt the basics have changed all that much.
The art and graphics in old books are great as well. I always like to think of older albums, books, and movies as a snapshot in time. It's fun to see a snapshot in time in such a specific niche.
https://www.amazon.com/Object-Oriented-Programming-COMMON-LI...