The modified version has some changes to cater for Firefox and some things still don't work. JIT compilation for example, so I've left the checkbox for this disabled by default. This does slow things down quite a bit but I'll enable it again when I find the problem. For IE JIT works fine and you can enable it. If you find any other issues I'd be keen to get feedback. Leave a comment here or email me. I've also put the modified version in a darcs repository available with:
Please send me any patches you'd like to apply.
(define d (js-eval "new Date();")) (display (js-invoke d "toString")) (newline)
(js-call (js-eval "jsAlert") "Hello World!")
(set-timeout! (lambda () (alert "Hello World")) 1000)
This example waits one second and displays the alert. Any Scheme function can be passed, including continuations:
(define abort #f) (define (yield) (call/cc (lambda (k) (set-timeout! k 10) (abort)))) (define (spawn thunk) (call/cc (lambda (k) (set! abort k) (thunk)))) (define (fib n) (yield) (if (= n 0) 0 (if (= n 1) 1 (+ (fib (- n 1)) (fib (- n 2))))))
This code allows you to spawn a single thread which will run in the background of the browser. That thread can call 'yield' to return control back to the browser for a brief time. A simple fibonacci function is provided which calls 'yield'. For example:
(spawn (lambda () (display (fib 10))))
This will return control immediately. You can carry on using the browser and the result will be displayed when the thread completes. A simple thread scheduler implementation would be an interesting exercise.