3 ms·
I don't know about "since 2005" but there are two features in the original CL spec which I find indispensable but which still have not made it into any other la
by lisper 5y ago
I don't know about "since 2005" but there are two features in the original CL spec which I find indispensable but which still have not made it into any other languages (AFAIK):
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
- dotancohen 5y agoWhen would you ever legitimately use #2? 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.
- moonchild 5y agoIn longrunning/high-availability applications, this sort of thing is necessary in order to avoid restarting and losing uptime or state. E.G. per nasa: > 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 (from https://flownet.com/gat/jpl-lisp.html https://flownet.com/gat/jpl-lisp.html)
- dotancohen 5y agoInteresting, thank you!
- lisper 5y agoAny code modification is a potential security issue. There is nothing special about dynamic class redefinition in this regard. 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.lisp https://github.com/rongarret/ergolib/blob/master/layer1/sql....
- mikelevins 5y agoI use Common Lisp in my day job, and I generally build software by livecoding, so I use this and other interactive programming support on a daily basis. Seems "legitimate" to me. I don’t want to have to stop my work-in-progress program running and lose all of the incremental state I’ve built just because I redefined a class or something.
- dotancohen 5y agoSo it's a feature that you would use during development, but not in the final (ha, ha, that never happens) state of the application?
- p_l 5y agoShinmera's Trial game engine, used in Kandria (which you can find on Steam), uses bits of the same machinery to implement the resourc system inside the game. IIRC it has separate classes for "unloaded entity" and classes for various types of resources, and the protocol (think interface) for them includes the generic function that loads them into memory. The implementation of said function for unloaded objects uses CHANGE-CLASS method redefine the instance in place - meaning all direct memory pointers to the class are still valid and you don't need to use extra layer of indirection.
- mikelevins 5y agoI can agree that the most common uses are for development in progress, but I wouldn’t go so far as to say I wouldn’t use those facilities in a fully worked-out program. A sibling comment offers one reasonable example. I’ve done similar things before and probably will do them again.
- bmitc 5y agoWhat is a generic function?
- pfdietz 5y agoIt's a function that has one or more required arguments, and a set of methods. Each method has a class (or an EQL specifier) associated with each argument. When the generic function is called, the best method for which each actual parameter is in the corresponding argument's class is invoked. Think of it like a method in ordinary OO, but it can dispatch on multiple arguments. 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_Lisp_Object_System https://en.wikipedia.org/wiki/Generic_function#In_Common_Lis... http://clhs.lisp.se/Body/07_f.htm http://clhs.lisp.se/Body/07_f.htm
- HansW3510 5y agoFor an interesting application, see how https://github.com/joaotavora/snooze#rationale https://github.com/joaotavora/snooze#rationale maps generic functions to HTTP/REST.