[racket] changing source code with application still running
50 minutes ago, Daniel Bastos wrote:
>
> Say I have some application running. I told the shell
>
> ./run_my_application &
>
> Now, while using it, I notice a bug somewhere. How do I change the
> code and see its new effect without shutting down and rerunning the
> application?
Here's an even shorter demo of what PG is talking about using the
Racket REPL:
(define (foo) (printf "Hey\n") (sleep 1) (foo))
(thread foo)
And after you see that it works:
(define (foo) (printf "Ho\n") (sleep 1) (foo))
This has several issues though. First, it uses the top level which
means that it's not as efficient as you might want. It's as if `foo'
is boxed or as if you're doing a hash lookup for the name on every
call. Second, it uses the toplevel, so you're losing the many other
benefits of using modules.
Third, and that's something that you'd need to deal with in CL too,
you want some convenient wrapper around the REPL so that you can do
the server hotpatching in some reasonable way. For example, some
network server that you can connect to instead of relying on a process
running in some terminal.
I have some code in my IRC client (which is still not public, and
that's still due to really silly reasons) that wraps the whole thing
conveniently -- there's a "handlers" subdirectory with racket files
that are all required dynamically, and whenever a file changes it
detects it and reloads the relevant file, carefully killing the
handlers that were there previously and registering the new ones
instead.
And even that suffers from additional issues -- the kind that you
can't really get around nicely... Things like wanting some piece of
persistent data that is not re-initialized when its file is reloaded.
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://barzilay.org/ Maze is Life!