variable renaming

This commit is contained in:
Danny Yoo 2012-03-05 17:10:26 -05:00
parent 3315d65f43
commit ce0e1259b5
10 changed files with 60 additions and 27 deletions

View File

@ -15,7 +15,7 @@
;; Let's attach the send-event function to a toplevel function on the window.
(void ((js-function (js-eval "function(send) { $(window).bind('message', function(e) { send(e.originalEvent.data); })}"))
(void ((js-function->procedure "function(send) { $(window).bind('message', function(e) { send(e.originalEvent.data); })}")
send))
;; js-function lifts JavaScript functions to regular function we can call.

31
js.rkt
View File

@ -1,3 +1,32 @@
#lang s-exp "lang/base.rkt"
(require "js/main.rkt")
(provide (all-from-out "js/main.rkt"))
(provide [except-out (all-from-out "js/main.rkt")
js-function->procedure
js-async-function->procedure]
[rename-out [-js-function->procedure js-function->procedure]
[-js-async-function->procedure js-async-function->procedure]]
js-function?)
(define raw-js-function?
(js-function->procedure (js-eval "function(x) { return typeof(x) === 'function'}")))
(define (js-function? x)
(raw-js-function? x))
(define (-js-function->procedure x)
(cond
[(string? x)
(js-function->procedure (js-eval x))]
[(js-function? x)
(js-function->procedure x)]
[else
(raise-type-error 'js-function->procedure "js-function or string" x)]))
(define (-js-async-function->procedure x)
(cond
[(string? x)
(js-async-function->procedure (js-eval x))]
[(js-function? x)
(js-async-function->procedure x)]
[else
(raise-type-error 'js-async-function->procedure "js-function or string" x)]))

View File

@ -159,9 +159,9 @@
// Lift JavaScript functions to Whalesong functions.
EXPORTS['js-function'] =
EXPORTS['js-function->procedure'] =
makePrimitiveProcedure(
'js-function',
'js-function->procedure',
1,
function(MACHINE) {
var f = checkJSFunction(MACHINE, 'js function', 0);
@ -177,9 +177,9 @@
});
});
EXPORTS['js-async-function'] =
EXPORTS['js-async-function->procedure'] =
makePrimitiveProcedure(
'js-async-function',
'js-async-function->procedure',
1,
function(MACHINE) {
var f = checkJSFunction(MACHINE, 'js function', 0);

View File

@ -8,8 +8,8 @@
call-method
$
js-function
js-async-function
js-function->procedure
js-async-function->procedure
window

View File

@ -22,8 +22,8 @@
load-script
js-function
js-async-function
js-function->procedure
js-async-function->procedure
)
(define (alert x)
@ -103,8 +103,8 @@
(error 'load-script "Not available outside JavaScript context."))
(define (js-function f)
(error 'js-function "Not available outside JavaScript context."))
(define (js-function->procedure f)
(error 'js-function->procedure "Not available outside JavaScript context."))
(define (js-async-function f)
(error 'js-async-function "Not available outside JavaScript context."))
(define (js-async-function->procedure f)
(error 'js-async-function->procedure "Not available outside JavaScript context."))

View File

@ -1,6 +1,3 @@
#lang s-exp "../../lang/js/js.rkt"
(require "../../web-world.rkt")
(declare-implementation
#:racket "racket-impl.rkt"
#:javascript ("js-impl.js")
#:provided-values (make-js-world-event))
#lang s-exp "../../lang/base.rkt"
(require "make-js-world-event.rkt")
(provide (all-from-out "make-js-world-event.rkt"))

View File

@ -0,0 +1,6 @@
#lang s-exp "../../lang/js/js.rkt"
(require "../../web-world.rkt")
(declare-implementation
#:racket "racket-impl.rkt"
#:javascript ("js-impl.js")
#:provided-values (make-js-world-event))

View File

@ -15,9 +15,10 @@
;; Let's attach the send-event function to a toplevel function on the window.
(void ((js-function (js-eval "function(x) { window.sendTheTick = x; }"))
(void ((js-function->procedure (js-eval "function(x) { window.sendTheTick = x; }"))
send-event))
;; js-function lifts JavaScript functions to regular function we can call.
;; js-function->procedure lifts JavaScript functions to regular
;; procedures that we can call.
(define (tick w v)

View File

@ -2,13 +2,13 @@
(require (planet dyoo/whalesong/js))
(define js-plus
(js-function (js-eval "function(x, y) { return x + y; }")))
(js-function->procedure "function(x, y) { return x + y; }"))
(define js-minus
(js-function (js-eval "function(x, y) { return x - y; }")))
(js-function->procedure "function(x, y) { return x - y; }"))
(define sleep
(js-async-function (js-eval "function(success, fail, n) { setTimeout(success, n) }")))
(js-async-function->procedure"function(success, fail, n) { setTimeout(success, n) }"))
"plus: " (js-plus 3 4)
@ -25,5 +25,5 @@
;; I need exception handling...
;;
;(define i-should-fail
; (js-async-function (js-eval "function(success, fail) { fail('I should fail'); }")))
; (js-async-function->procedure "function(success, fail) { fail('I should fail'); }"))
;(i-should-fail)

View File

@ -7,4 +7,4 @@
(provide version)
(: version String)
(define version "1.221")
(define version "1.222")