#lang scribble/manual @(require planet/scribble (for-label (this-package-in main) racket/base)) @author+email["Danny Yoo" "dyoo@hashcollision.org"] @title{browser-evaluate: evaluate JavaScript expressions in the browser through Racket} @centered{@smaller{Source code can be found at: @url{https://github.com/dyoo/browser-evaluate}.}} @section{Introduction} This library allows you to send JavaScript expressions from Racket into a web browser. Furthermore, the library provides hooks to send string values from that evaluation back into Racket. As a simple example, evaluating the following: @codeblock|{ #lang racket/base (require (planet dyoo/browser-evaluate)) (simple-js-evaluate "alert('hello world!');") }| should bring up a browser window in which an alert dialog should display. The library depends on the browser to do the JavaScript evaluation, and sends values back and forth between the browser and Racket. For more fine-grained control over evaluation, you can use @racket[js-evaluate], which allows string values to be returned back from JavaScript back to Racket. The JavaScript code should call the @litchar{$SUCC} success function to send the value back into Racket. For example: @codeblock|{ #lang racket/base (require (planet dyoo/browser-evaluate)) (define result (js-evaluate #< . void)]) (any/c -> (values string number))]{ (Low-level function that's used to implement @racket[simple-js-evaluate] and @racket[js-evaluate].) Produces a JavaScript evaluator that cooperates with a browser. The JavaScript-compiler is expected to write out a thunk. When invoked, the thunk should return a function that consumes three values, corresponding to success, failure, and other parameters to evaluation. For example: @codeblock|{ #lang racket/base (require (planet dyoo/browser-evaluate)) (define my-eval (make-evaluate (lambda (program op) (fprintf op #<