6 ms·
Rebuilding those dynamic libraries requires external build system and compiler invocation. In Lisp you just use the REPL.
by yarrel 12y ago
Rebuilding those dynamic libraries requires external build system and compiler invocation. In Lisp you just use the REPL.
- orbifold 12y agoOf course, but in practice that doesn't really matter. Recompilation time for small changes is negligible and if you have a sane build system setup is pretty much invoked the same way you would load new code into a repl. In the case of shader compilation, compiling and linking actually is exposed as library functions, so you have complete control over how to do that. Most of the dynamic features a repl provides, like introspection and so on is also available with a good debugger, depending on the scope of the project you can also just use Lua as a scripting language to get the majority of the benefits that Lisp has. Moreover nested parentheses sort of pale, if you can visualize most of your state in much more powerful ways on the screen. Since you have complete control over memory, you can implement time travelling debugging pretty easily, you just need a good ordinary debugger, a way to record all input to the game (easily done if you have clean separation between game and platform code) and a way to snapshot the game state at some point in time (also easy if you allocate all memory ahead of time and only let the game code use your memory allocators).
- malisper 12y agoCould you redefine a class/structure and update every instance of it at runtime? For example, let's say you are currently representing complex numbers in rectangular form. Is it possible to convert every existing instance to polar form, at runtime, without breaking any code?
- orbifold 12y agoWell no, the representation of game state and input have to remain the same ^1. I guess in lisp you could more easily write a function that maps the previous representation into the new one. Here is an example of what kind of interactive code reloading I have in mind: https://www.youtube.com/watch?v=xrUSrVvB21c https://www.youtube.com/watch?v=xrUSrVvB21c Admittedly it is more of a hack than in a Common Lisp system, but still. 1) EDIT: At least in the most simple design. Nothing prevents you from optionally stopping the simulation, serialize a snapshot of the sate to disk, change the representation of complex numbers or whatever, together with the data serialization routines and continue.
- malisper 12y ago> I guess in lisp you could more easily write a function that maps the previous representation into the new one. Lisp provides a simple way redefine classes. There is a generic function (basically a function that is extensible), update-instance-for-redefined-class[0], which is called on instances of the old representation to map them to the new one. All a programmer has to do is extend it with the behavior they want. Coincidentally, the link I gave shows how to do this to change the representation of a point from Cartesian coordinates to polar coordinates. [0] http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/stagenfun_upd_efined-class.html http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec...
- yoklov 12y agoThat's a pretty ridiculous use case. I'd think if you wanted to make a change this drastic, having to reload the game wouldn't be a huge deal. I mean, you'd want to make sure everything up to the point you were at still works anyway. (Besides, this is an awful way to represent 2D points in practice). FWIW, It's certainly possible to write code that reorders struct fields on changes, but it requires either boilerplate, macro hell, or parsing part of your C code for structure declarations (I've heard this sounds worse than it is). Arbitrary mappings are more difficult and IMO not worth the trouble. Not to say this technique doesn't have downsides. It's downsides are so huge that IMO it's benefits aren't worth it, unless you were already going to program in that style to begin with. - No pointers to static memory (globals, vtables, and pointers to string literals or constant arrays are out) - No pointers to functions (most other ways of emulating dynamic dispatch are out). - You need to use custom allocators that work out of your game state block. And since you have no global or thread local state... you need to hope that any library you want to use allows you to provide a context for any memory allocation it wants to do. Most don't. - etc, etc, etc... you get the picture. Essentially, you need to write your game like its 1995. And sure, maybe you can get this in lisp without any limitations (I don't know, but I believe it if you say you can), but the reality we live in is that it's unrealistic to write production-quality game engines in lisp. I've heard it's used for scripting and AI in some places (probably just Naughty Dog, tbh), but most of the code that goes into a game isn't in script, unless it's a slow game.
- malisper 12y ago> That's a pretty ridiculous use case. It was just an example. I never said you would actually want to do it. > maybe you can get this in lisp without any limitations See my response to orbifold: https://news.ycombinator.com/item?id=8943113 https://news.ycombinator.com/item?id=8943113 > I've heard it's used for scripting and AI There are many different versions of lisp, some of them are used for scripting, but most implementations of Common Lisp could be used for almost anything. > most of the code that goes into a game isn't in script, unless it's a slow game. Write version 0 in a high level language. Figure out the design and representation. Then rewrite the slow parts in a more efficient language.
- 12y ago
- Gurkenmaster 12y agoYou can do that in Java with the DCEVM but the latest release is slightly out of date so you have to compile the whole OpenJDK yourself. I blame Oracle for not integrating it in the OpenJDK.