[racket] problems running moby from source

From: Danny Yoo (dyoo at cs.wpi.edu)
Date: Mon Oct 25 16:23:47 EDT 2010

Hi Sigrid,

I'm revamping Moby; it's being mostly subsumed by my js-vm PLaneT package.


To install, evaluate the following at your DrRacket REPL:

   (require (planet dyoo/js-vm:1:2/info))

This will install js-vm and the tools.

Once that's installed, restart DrRacket.

There should now be the following menu options under the Racket submenu:

   * Create Javascript Package
   * Run Javascript in Browser


The first will create a .zip package at a specified place, and the
latter will start up a web server and serve a page that runs the
currently-edited program.

As an example, enter the following as "test.rkt":

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#lang planet dyoo/js-vm:1:2

(printf "hello world\n")
(check-expect (* 3 4 5) 60)
(current-seconds)
(image-url "http://racket-lang.org/logo.png")
(check-expect
       (big-bang 0
                 (on-tick add1 1)
                 (stop-when (lambda (x) (= x 10))))
       10)
"last line"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Save the file, and then press Run.  The interactions should evaluate
up to the image-url expression, after which case the repl will error
out with "Must be evaluated within Javascript".  As long as your
program is not accessing anything Javascript-specific, you should
still be able to run and test your programs under DrRacket.  (big-bang
is currently a Javascript-specific function.)

Next, choose "Run Javascript in Browser". DrRacket should bring up a
status window, as well as opening up a web browser with the currently
running program.

Finally, choose "Create Javascript Package".  DrRacket will prompt for
a place to put the zip file, and then generate a .zip archive; its
contents will be the files that were served under "Run Javascript in
Browser."



The falling ball example will be this:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#lang planet dyoo/js-vm:1:2

(define-struct world (radius y))

;; The dimensions of the screen:
(define WIDTH 320)
(define HEIGHT 480)

;; The radius of the red circle.
(define RADIUS 15)

;; The world is the distance from the top of the screen.
(define INITIAL-WORLD (make-world RADIUS 0))

;; tick: world -> world
;; Moves the ball down.
(define (tick w)
  (make-world RADIUS (+ (world-y w) 5)))


;; hits-floor?: world -> boolean
;; Returns true when the distance reaches the screen height.
(define (hits-floor? w)
  (>= (world-y w) HEIGHT))

;; We have some simple test cases.
(check-expect (hits-floor? (make-world RADIUS 0)) false)
(check-expect (hits-floor? (make-world RADIUS HEIGHT)) true)

;; render: world -> scene
;; Produces a scene with the circle at a height described by the world.
(define (render w)
  (place-image (circle RADIUS "solid" "red") (/ WIDTH 2) (world-y w)
               (empty-scene WIDTH HEIGHT)))

;; Start up a big bang, 15 frames a second.
(check-expect (big-bang INITIAL-WORLD
                           (on-tick tick 1/15)
                           (to-draw render)
                           (stop-when hits-floor?))
              (make-world 15 480))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


As you might notice, some of the names of symbols have changed from
Moby 2.  I'll be releasing documentation for the new system shortly.


Posted on the users mailing list.