200 points · by oumua_don17 · 4y ago · 113 comments
https://en.m.wikipedia.org/wiki/Dynamic_Analysis_and_Replann...
Written in Lisp at the time and widely successful to the point it paid back many times over the investment DARPA put into the language
Now the question for anyone who may know, are descendant systems still being written in Lisp?
For example, I just saw an old paper [1] where the author implements dynamic compilation from Lisp, to Lisp, in Lisp, for parsers. One describes the language to be parsed, in a high and abstract level in a DSL in Lisp. The Lisp program then compiles that definition into to a low-level sequence of unboxed boolean and arithmetic ops and conditionals in Lisp which, being primitives with direct machine code equivalents, the Lisp compiler can translate into reasonable machine code. The end result was probably only a few times slower than doing the recognizers directly in C.
Not so different from the usual parser generator technique. But the nice part of doing it that way is that you retain the full Lisp system; your generated blobs of "machine-level Lisp" are still just another Lisp object, so you can take your generated functions and single-step it in interpretation, or transform it further. I suspect that's a big part of why Lisp was so popular for so long. Other languages provide similar capabilities now, though sometimes not so general in ability. But for a long time, this sort of meta-programming where you write the program at the high level to generate the code at the low level for you, was basically a proprietary superpower for Lisp.
[1] https://www.plover.com/~mjd/misc/hbaker-archive/Prag-Parse.h...
What are some interesting libraries or language features developed since 2005 that haven't yet made their way to other languages? Not a simple "Do X" library that a C programmer could easily copy, but something more like CLOS, contracts, or pattern matching that are cross-cutting.
Some people hate Lisp's heavy reliance on parenthesis and there have been so many languages that try to make a "Lisp without parenthesis", but to me they're missing half of what makes Lisp great.
I find programming in and reasoning about Lisp way, way easier than other languages. There's very little syntax to stand in the way or remember and the verbose way Lisp is written helps make Lisp programs self-documenting and way easier to understand than other languages.
This is super useful when doing a lot of language hopping or when coming back to the language/program after being away from it for a long time. Because of this I can quickly come back up to speed with the program and it also makes more larger and more complex programs more comprehensible -- that is, of course, if you don't use macros to turn Lisp in to some harder to understand language.
One very recent library that might be of interest is "just" a new regex library (https://applied-langua.ge/posts/omrn-compiler.html) but it leverages one unique design choice Lisp made in that you have access to the language's compiler at runtime, it's not a fenced-off separate program only used to create a runtime executable. The compiler can (and in SBCL's case does) optimize and produce assembly code, SIMD instructions can be used too, so this regex lib is very fast while not being that much code.
This is best understood as having no phase separation between compile time and run time. Effectively, languages that are so designed do everything at compile time, up to and including running the actual program.
Though sometimes they can practically recover the phase separation by "extracting" a program that can be compiled in a single step and ran as a conventional binary. For example, a LISP program for doing math may support "extracting" a custom function evaluator or numerical-symbolic solver written in FORTRAN.
However even counting with upcoming C++23 features, Lisp is much more ergonomic for this kind of stuff.
Most powerful one today by combination is actually JS inside Chrome, you naturally have the REPL that can do things.
But REPL's are good for the first prototyping whilst later on you might have modules (CL might make things inspectable?) that try to hide things (think JS/TS modules), Chrome however is pretty damn good at runtime detecting more or less incremental updates so you can just rewrite code and re-save the source files and Chrome will replace the function bodies in-situ without any state rebuilding or reloading being necessary.
Of more conventional languages, MSVC has had C/C++ Edit-Continue (as long as you didn't change type/function signatures) since ca 1998, it's a descendant of this that MS was hyping last year with Hot-Reloading for C# with body replacement (on top of the interactive shell("REPL") that has been in Visual Studio for years).
Especially the conventional ones might not be as flexible as the Lisp ones(but handle many practical cases fairly well) but all dynamic "scripting" languages like JS/Python/Lua,etc has been able to do most repl-y things fairly well from day 1.
Take, for example, Common Lisp's UPDATE-INSTANCE-FOR-REDEFINED-CLASS (http://clhs.lisp.se/Body/f_upda_1.htm). If you redefine a class in a running program, Lisp notices and the next time control touches an existing instance of the class, UPDATE-INSTANCE-FOR-REDEFINED-CLASS is automatically called to reinitialize the instance to reflect the new definition.
That's not all there is to it, of course. For example, how does Lisp know how to reinitialize the instances for the new definition? The Common Lisp standard also defines a complete suite of features to answer that question.
Smalltalk provides equivalent features.
Lots of languages have repls. Some of them support hot reloading. These are not the same kind of thing as automatically noticing that a definition has changed, and that implies that any time you touch a previously-created instance of that definition the runtime needs to automatically catch it and provide facilities (interactive when needed) to dynamically fix up the data to conform to the new definition.
Why would any language define such features? To support a specific style of programming, one in which the program is already running, it just doesn't have all the features you want it to have--so you tell it how to add them, while it runs, and test each new feature immediately, as soon as you've told the program how to do it.
Very few languages support the comprehensive whole-system approach to livecoding that Common Lisp and Smalltalk do. These are not new features, though; they've been around for decades.
If they were the same, you'd load up a repl of your entire codebase. Now you'd dynamically update the part you're working on, test it live against your current environment, and finally save it to move to another thing. When errors happen, you just drop into the debugger to find the issue. If you missed a call site or two, you'll probably catch it here. Because it's instantaneous, it's not painful. I'll have a REPL open pretty much all the time when messing around with CL.
In JS (my day job), this wouldn't work at present if for no other reason than directly replacing a function is impossible. You'd create a second instance of a function, but all the old references from other places in the code would remain stuck with the old version.
JS falls back to "hot reloading" which is literally "restart the whole JIT" which means that you have to warm the JIT up again and (more importantly) that all your state disappears.
You make a change then wait a while for everything to recompile and run. Then you have to write/execute a bunch of code to get your state back to where it was. When the error is thrown, you now have to look through the things for that call site you missed, save, and reload everything all over again. Rinse and repeat. This heavily disincentivizes interactive and incremental development in favor of massive changes then trying everything out at once.
Just hitting a shortcut and getting the code executed using everything loaded into the REPL and getting inline results is great.
It helps that Clojure only has expressions and no statements as well, so every form can be run and it will return something.
Here's what I mean, this is me doing 2021-Day2 AoC puzzle part 1. WHen this pops up
=> foo
Next to a line, it's because I've hit CTRL+Enter on that line to evaluate the form.https://www.youtube.com/watch?v=5HHLT2_a1tI
(You'll need to bump to 1080 resolution otherwise its probably unreadable)
My day job is C# and JS, I can't get anywhere close to this interactivity with my code. As the complexity of the code grows this becomes even more powerful.
@phoe-krk's book on it, https://news.ycombinator.com/item?id=24867548 is very good.
Smalltalk can do it, too.
It adds static typing to Common Lisp, while (I believe) still allowing one to escape to the dynamic world when needed. Sure, there are statically-typed languages, but I don't know of another dynamic language in which something like Coalton has been done.
Now in terms of interesting things, check out European Lisp Symposium https://european-lisp-symposium.org/
The talks from this year were highly entertaining
The other really cool thing in CL IMO is Allegro Cache - in memory datastore that is a joy to use
i think this is precisely the point of coalton. cl allows quite handy compiler optimizations and having the option to drop into a native statically typed environment just gives more bang to your lisp ;)
coalton is not lispy, sure, but neither is the loop macro, yet it is probably the most powerful looping mechanism in any language :)
If i change the code at all, i just press the same key combo and see the new result. It remembers all the state of what i've done up to that point too so i don't need to mess around setting up the call with data to feed in for example.
The closest i can find to replicating this is the various hot-reload implementations in other languages but they all incur some kind of delay (naturally, because they're all doing a lot more work behind the scenes) which ruins the use of this feature, it stops you using it to evaluate your thought process in realtime. They also don't render the results inline - mostly because the syntax of JS/TS and other languages doesn't really lend itself to this kind of usage.
Imagine that your shell was like those notebooks, and not only you can interact with the whole OS, you can even change existing notebooks dynamically by reloading code that they depend on, e.g. a displayed image gets a new effect added to it.
The best analogue i can come up with is a sql session connected to a live database.
Proper tail calls. Technically not part of the CL spec, but implemented by the best CL variants (and by scheme), they allow a lot of expressive power. You won't find this ANYWHERE on the top 20 except for JS where it is technically part of the spec, but Google and Mozilla refused to implement leaving just Safari/JSC to have 100% ES6 spec compliance 7 years after the spec was finished.
Macros get overstated perhaps, but there are almost zero non-lisp languages that implement them and none of them implement macros ergonomically. In a language like JS, you'll often see a kind of DSL where they attempt to use closures and super-dynamic objects to create templates.
I see this a lot in React where you'll have huge config objects passed in and then very extensive branchy and loopy code to turn all the bits on an off. This is a poor man's macro. In a lisp, you would do all this stuff at compile time with all that inefficient branchy stuff executed once at compile time rather than millions of times on each of the thousands/millions of machines your code is running on.
The REPL has been mentioned several times, but it really is that good and nothing from other languages compares. People stress about "writing unit tests" because technically correct types doesn't mean your program actually works. In my time writing JS vs TS, I've seldom found that type errors were the problem aside from making the type checker happy. Most errors are in what the code actually does or does not do. The instant feedback from the entire system is far superior to unit tests because it can catch things that your unit tests might not be testing for.
Dynamic, but definable types is another advantage. You start out without a bunch of specific types which is better for getting things done, but can then add in type hints either as documentation or as a way for the compiler to spit out fast code. People may be down on dynamic code, but the truth is that the world is dynamic and runtime type checks are far safer than static types where they are then thrown out and you hope for the best. Because of the REPL-driven development, type errors are almost non-existent in practice.
uh, what? plenty of popular languages have all of those things.
PHP, Perl and Swift all have first-class functions, lambdas and closures although I'd agree that that's not "most." This is probably getting too much into semantics, but aren't functions in JS just objects themselves? ;)
>People stress about "writing unit tests" because technically correct types doesn't mean your program actually works. In my time writing JS vs TS, I've seldom found that type errors were the problem aside from making the type checker happy. Most errors are in what the code actually does or does not do. The instant feedback from the entire system is far superior to unit tests because it can catch things that your unit tests might not be testing for.
I don't think having a "live" system like CL precludes the need for unit tests. Sure, it's beneficial to be able to play around with code right away, but unless you're planning on manually running through the same tests again and again, how do you know you've not introduced a regression at some point?
Perl does have closures, but does not have lambdas as I recall (only subroutines) plus, but I didn't think it was particularly popular today. Dart and Swift do have all three of these things, but they also aren't particularly popular outside their niche mobile domain (or outside OSX in the case of Swift). Python has first-class functions and closures, but the lambdas are nerfed into near uselessness.
PHP has a Closure class, but you must manually populate this class with whatever things you want to save. This is hardly what would commonly be accepted as a closure.
> I don't think having a "live" system like CL precludes the need for unit tests. Sure, it's beneficial to be able to play around with code right away, but unless you're planning on manually running through the same tests again and again, how do you know you've not introduced a regression at some point?
You are quite correct. Unit tests are still required, but the coverage you get when running stuff manually is still usually better for the same reason that a person clicking buttons on your UI will find tons of issues your unit tests overlooked. By running your new code inside of the whole system, you are also integration testing on the fly. I'd also add that it is possible to use some of your setup state for unit tests later.
The thing is, though, not all tests are worth automating.
I generally start work by sketching out a strawman representation of what I think I'm doing, then interrogating it interactively to find out how reality differs from my naive understanding. As my understanding improves, I refine the representation incrementally and interactively, and refine the interrogations right along with it.
You can think of those interrogations as embryonic APIs and interactive unit tests, but most are not worth formalizing. They're ephemeral. The details they're interrogating are likely to change beyond recognition in a short time until discovery reveals the real shape of things.
Once the real shape starts to emerge from the lump of clay, the representation turns into actual data structures and the interrogations turn into actual APIs and formal tests.
I probably spend more time testing than in any other single activity while working in Lisp. I test pretty much every single expression interactively as soon as it's written, because it's so quick and effortless to do so.
But most of those tests are not worth formalizing. Many of them will be executed one time and then never again. Others will be useful long enough to earn a temporary home in a source file for a while.
The formalized unit and integration tests are the ones that have survived iteration, that are connected to structures and APIs that have survived and developed into something real.
And that's the process, pretty much: rough sketch; interactive experimentation to discover what it really ought to be; formalization of discovered features (including tests that are worth automating).
This was true at one point, but most popular languages have them now, don't they? Even C++ and Java have them now (and have for a while).
Likewise, C++ basically has function pointers (though I'd hardly put C/C++ in the same category). True closures aren't really possible without garbage collection or manually specifying the closure, but at that point, the closure is just a glorified struct and loses all its ergonomic advantages.
A quick Google search tells me the "top 20" includes Python, JavaScript, Java, C#, C, Go, Swift, PHP possibly Ruby/Perl/Kotlin/etc. I can't think of a single one that doesn't have either first-class functions or some form of closures.
> Proper tail calls.
This is an optimization issue for most languages, and they have made the trade-off of keeping a stack trace vs. optimizing it away. Having it in the Scheme spec was incredibly contentious and caused many heated debates.
> none of them implement macros ergonomically.
I think this really depends on what you mean "ergonomically." That's a weasel word in this context. Because there are two camps. There is the CL Lisp-2 that feels they should be allowed to use LIST as a variable in a macro so they went and created a whole namespace just for functions but are perfectly fine with the ugly GENSYM hack. Then there is the Scheme camp that failed to come up with a suitable hygienic replacement for DEFMACRO for like 20 years. Macros have been broken in LISP world longer than most of us have been alive.
> React where you'll have huge config objects passed
Not sure what you're referring to here. A/B testing is a thing. Can't do that with macros. Hydration is also a thing, because of SSR. Maybe you're seeing that?
> REPL-driven development, type errors are almost non-existent in practice
ehhhh. No. And I say this as someone that generally prefers dynamic over static typing. You can easily have objects in your REPL that were the result of previous bugs and get your app in an inconsistent state. You either reload, or spend your entire life cleaning up memory and hoping you get it right. There is no silver bullet here, despite what others have commented on. Because you're talking about schema migrations here. Bad data structures have to be transformed to good data structures. Or you'll see bugs in the REPL that aren't actually bugs in the source. Keeping the REPL and source in sync is also tedious, to put it mildly.
Look into Erlang does and what is required to get live code swapping correct. It's a headache that is only worth it in very niche apps (like massive telecom systems). It doesn't make sense doing this during development. Much saner to just reload and start from a fresh, consistent point. Otherwise you will spend time hunting down bugs that do not exist outside your REPL.
It's an optimization issue for no languages; it's an optimization issue for some language implementations.
At the language level, it's a resource management (garbage retention) issue that leads to an expressiveness problem. See Clinger's papers on safety-for-space (e.g. [1]) and Felleisen's paper on expressiveness [2]. Support for proper tail calls in a language implementation also sometimes makes program execution faster, but that's not the main motivation.
[1] https://www.cs.tufts.edu/~nr/cs257/archive/will-clinger/prop... [2] https://www.sciencedirect.com/science/article/pii/0167642391...
Most of them don't have all of these features together and they often have incredibly bad versions of those features that are basically unusable.
> This is an optimization issue for most languages, and they have made the trade-off of keeping a stack trace vs. optimizing it away. Having it in the Scheme spec was incredibly contentious and caused many heated debates.
The JS stack already goes away the second you do anything asynchronous. As this is something you do frequently, stack traces are already incredibly short.
Meanwhile, the alternative for the use cases of PTC is loops and I don't hear complaints that loops don't save your state.
It's in the spec, it should be implemented.
As to Scheme, you won't find anyone today arguing that PTC is bad. The bigger argument would be about how full continuations are a performance disaster.
> I think this really depends on what you mean "ergonomically."
Infix macro systems are terrible to use compared to S-expr macros and I don't think this is anywhere close to controversial. Can you point to a counter-example?
The best infix example I know of is Dylan, but not only is that language barely infix (its S-expr foundations are very apparent) and they still just aren't as easy to use.
> ehhhh. No. And I say this as someone that generally prefers dynamic over static typing. You can easily have objects in your REPL that were the result of previous bugs and get your app in an inconsistent state. You either reload, or spend your entire life cleaning up memory and hoping you get it right. There is no silver bullet here, despite what others have commented on. Because you're talking about schema migrations here. Bad data structures have to be transformed to good data structures. Or you'll see bugs in the REPL that aren't actually bugs in the source. Keeping the REPL and source in sync is also tedious, to put it mildly.
How does this entire bit have anything to do with dynamic vs static typing? You could have a REPL with static typing if you truly wanted.
In any case, reloading data from the code isn't that difficult and most data will be held in closures which means you can decide exactly how far up you want to replace local data (and if you're going about it smartly, you have created a few "mocks" to work with that can be used to refresh data).
The absolute worst case (restarting the REPL) is what other languages would force you to do anyway which still means you have a lot to gain for most development and bugfixing and absolutely nothing to lose.
As to data is held in a database, then you have all the same problems in other languages except that fixing these issues from the REPL is generally easier because you are already connected and ready to start fixing things.
> Look into Erlang does and what is required to get live code swapping correct.
BEAM is an amazing platform, but a REPL for development and live code swapping are two different discussions. Doing REPL work on production systems has a very big chance of catastrophic damage and I wouldn't recommend it.
Going from CL (and scheme probably too) to macros in any other language is like going from a lambo to a tricycle. It's one of the things I miss most about CL.
I also love the live-editing aspect of CL. When I was doing game programming with it, being able to replace functions while running was incredibly useful. You don't have to re-create all your state, you can jsut live-edit a function and boom fix a bug or add a new feature right there. Very good for exploratory programming with lots of otherwise-hard-to-replicate state.
CL has a very advanced TDD. You actually develop by executing snippets in REPL and pull them all together in a function (already tested!).
1. Generic functions
2. Being able to redefine a class and have existing instances of that class be automatically updated to conform to the new definition
If e.g. an API wants to support monkey patching that's a decision that can be made. But thinking that any e.g. plugin or addin could could redefine extant class instances sounds like a nightmare, and a security issue just waiting to happen.
> The Remote Agent software, running on a custom port of Harlequin Common Lisp, flew aboard Deep Space 1 (DS1), the first mission of NASA's New Millennium program. Remote Agent controlled DS1 for two days in May of 1999. During that time we were able to debug and fix a race condition that had not shown up during ground testing. (Debugging a program running on a $100M piece of hardware that is 100 million miles away is an interesting experience. Having a read-eval-print loop running on the spacecraft proved invaluable in finding and fixing the problem
I use it for development and deployment. I can deploy new code without having to take my application down. In fact, not only do all my existing instances get updated, but I also use an ORM [1] that automatically updates my database tables too.
[1] https://github.com/rongarret/ergolib/blob/master/layer1/sql....
There's also some interesting stuff on top of this (method combinations) that allow multiple methods to be invoked and their results combined.
https://en.wikipedia.org/wiki/Generic_function#In_Common_Lis...
https://github.com/SJ001/AI-Feynman/blob/master/aifeynman/sy...
I talk about it in my portfolio, it's Guesser 1.0 and Guesser 2.0.
https://github.com/daniel-cussen/portfolio/blob/master/portf...
Any tips for groking the package/namespace system? I've taken a couple runs at CL and that's where my brain always breaks down.
I very seldom tried Racket. CL picked my interest, and no language feature in a Scheme was attractive enough to me. CL seemed the most capable of all Lisp dialects, it seemed the most robust (a long history of industrial success stories), when I searched for CL libraries I found a lot, less so with Racket, etc. And so, the more I committed to learning and building stuff in CL, the less likely I was to switch to another Lisp. (Clojure? It takes so much resources when starting up, especially compared to CL, and I can't even install a library in a running REPL. That's my excuse for my disgust and fear of Java). I compiled some things lispers say about Racket: https://gist.github.com/vindarel/c1ef5e043773921e3b11d8f4fe1... and it makes me want to stay in my comfy CL environment (built with sweat).
I myself was never annoyed with the lisp-1/2 thing… You like the fact that in lisp-1 we can call a function given as reference directly, without `funcall`? Well, we can do that in CL, it's a `setf` away. It turns out we don't and it's alright.