[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Dynamic updating



>  >Lisp allows you to enter a running image, build up a lot of state by
>  >running programs, and then at that point load new definitions. This
>  >gives product maintainers the powerful ability to have customers load
>  >patches that can fix bugs in running programs without requiring those
>  >programs to be exited. The value to a customer in some situations can
>  >be immeasurable.
>
> In hopes of not starting any language wars on this very high S/N mailing
> list I would like to know if this is a property of CL itself or is this
> possible in mzscheme as well?

MzScheme does this just fine.  Comes in very handy when debugging
server-style applications, since you can modify code without restarting the
server.  The applications for runtime behavior modification go way beyond
that, though.

Here's a little demo, which redefines a function being used by a running
thread:

; peephole is global variable to see what's going on in our thread
(define peephole 0)

; peek is a function to display a few snapshots of peephole
(define (peek)
  (do ((n 4 (- n 1)))
    ((zero? n))
    (sleep 0.1)
    (display peephole)(newline)))

; looper loops and repeatedly updates peephole
; with the value of a function named "bar"
(define (looper) (set! peephole (bar peephole)) (looper))

; the initial version of bar
(define (bar x) (+ x 1))

; start running the looper function in a separate thread
(define loop (thread looper))

; take a look at what we can see through the peephole
; should print a few numbers
(peek)

; redefine bar
(define (bar x) "MzScheme rules!")

; take another peek to see the effect of redefining bar
; should print a statement of fact
(peek)

; stop the thread
(kill-thread loop)