2 ms·
No better example of this than Racket. Function application itself is an overridable function. (f 1 2 3) compiles to something like (#%app f 1 2 3). And you ca
by srcreigh 3y ago
No better example of this than Racket.
Function application itself is an overridable function. (f 1 2 3) compiles to something like (#%app f 1 2 3). And you can hook into that.
Runtime type checking, stack traces, debuggers..
- Blackthorn 3y agoYou used to be able to do fun stuff like that in clojure but it ended up being axed in the name of performance. (Well, I guess you still can, but the standard library is off limits now basically.)
- gus_massa 3y agoIn most cases, the new definition of #%app is a small wrapper around the standard one, with some special case. If the new definition is small enough, the Racket compiler can inline it and hopefully detect that it's the standard case and you get the same speed at the run time. In some cases, it may be useful to use a macro to "force" the inlining, but it may increase the total size of the code. There are a few languages implemented in Racket that do this, https://docs.racket-lang.org/rackjure/index.html https://docs.racket-lang.org/rackjure/index.html https://docs.racket-lang.org/lua-manual@lua-lang/index.html https://docs.racket-lang.org/lua-manual@lua-lang/index.html that redefine the #%app and ITRC in most case get the fast application after the compilation. In any case, if someone has a similar project with a custom #%app that is too slow, hey can ask using github or discourse and I(we)'ll try to help. In some case it's impossible, but in other case some tweaks make the redefinition of #%app more optimizer friendly.