adding rough documentation with example on using whalesong functions from javascript
This commit is contained in:
parent
c030b53333
commit
10699d6dc9
|
@ -239,10 +239,22 @@ web browser, we should see a pale, green page with some output.
|
||||||
@;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
@;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
Whalesong also allows functions defined from Racket to be used from
|
Whalesong also allows functions defined from Racket to be used from
|
||||||
JavaScript. As an example, we can take the boring @tt{factorial}
|
JavaScript. As an example, we can take the boring @emph{factorial}
|
||||||
function and define it in a module called @filepath{factorial.rkt}:
|
function and define it in a module called @filepath{fact.rkt}:
|
||||||
|
|
||||||
@filebox["factorial.rkt"]{
|
@margin-note{
|
||||||
|
The files can also be downloaded here:
|
||||||
|
@itemlist[@item{@link["http://hashcollision.org/whalesong/fact-example/fact.rkt"]{fact.rkt}}
|
||||||
|
@item{@link["http://hashcollision.org/whalesong/fact-example/index.html"]{index.html}}]
|
||||||
|
with generated JavaScript binaries here:
|
||||||
|
@itemlist[
|
||||||
|
@item{@link["http://hashcollision.org/whalesong/fact-example/fact.js"]{fact.js}}
|
||||||
|
@item{@link["http://hashcollision.org/whalesong/fact-example/runtime.js"]{runtime.js}}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@filebox["fact.rkt"]{
|
||||||
@verbatim|{
|
@verbatim|{
|
||||||
#lang planet dyoo/whalesong
|
#lang planet dyoo/whalesong
|
||||||
(provide fact)
|
(provide fact)
|
||||||
|
@ -257,13 +269,13 @@ function and define it in a module called @filepath{factorial.rkt}:
|
||||||
Instead of creating a standalone @tt{.xhtml}, we can use @tt{whalesong} to
|
Instead of creating a standalone @tt{.xhtml}, we can use @tt{whalesong} to
|
||||||
get us the module's code. From the command-line:
|
get us the module's code. From the command-line:
|
||||||
@verbatim|{
|
@verbatim|{
|
||||||
$ whalesong get-javascript factorial.rkt > factorial.js
|
$ whalesong get-javascript fact.rkt > fact.js
|
||||||
$ ls -l factorial.js
|
$ ls -l fact.js
|
||||||
-rw-r--r-- 1 dyoo dyoo 27421 2011-07-11 22:02 factorial.js
|
-rw-r--r-- 1 dyoo dyoo 27421 2011-07-11 22:02 fact.js
|
||||||
}|
|
}|
|
||||||
|
|
||||||
This file does require some runtime support not included in
|
This file does require some runtime support not included in
|
||||||
@filepath{factorial.js}; let's generate the @tt{runtime.js} and save
|
@filepath{fact.js}; let's generate the @tt{runtime.js} and save
|
||||||
it as well. At the command-line:
|
it as well. At the command-line:
|
||||||
@verbatim|{
|
@verbatim|{
|
||||||
$ whalesong get-runtime > runtime.js
|
$ whalesong get-runtime > runtime.js
|
||||||
|
@ -272,7 +284,7 @@ it as well. At the command-line:
|
||||||
}|
|
}|
|
||||||
Now that we have these, let's write an @filepath{index.html} that uses
|
Now that we have these, let's write an @filepath{index.html} that uses
|
||||||
the @racket[fact] function that we @racket[provide]ed from
|
the @racket[fact] function that we @racket[provide]ed from
|
||||||
@filepath{factorial.rkt}.
|
@filepath{fact.rkt}.
|
||||||
@filebox["index.html"]{
|
@filebox["index.html"]{
|
||||||
@verbatim|{
|
@verbatim|{
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user