-
Notifications
You must be signed in to change notification settings - Fork 3
/
js-vm.scrbl
1265 lines (986 loc) · 33.2 KB
/
js-vm.scrbl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#lang scribble/manual
@(require planet/scribble planet/version)
@(require (for-label (planet dyoo/js-vm/image/image))
(for-label (planet dyoo/js-vm/jsworld/jsworld))
(for-label (planet dyoo/js-vm/main)))
@(define (js-vm)
(emph "js-vm"))
@title{@js-vm[]: Javascript virtual machine for Racket}
@author[(author+email "Danny Yoo" "[email protected]")]
@js-vm[] provides tools to develop Racket programs that run
in Javascript. It provides a Javascript runtime that interprets
Racket bytecode, functions for building and testing packages of
translated code, and libraries to use features of a web-browser's
environment.
This project is intimately related with @hyperlink["http://www.cs.brown.edu/~sk/Publications/Talks/Moby-Bootstrap/"]{Moby}, as Moby uses @js-vm[] as its underlying runtime.
@section{Quick Start}
To make sure @js-vm[] is working, save the following program
as @filepath{test.rkt} in some working directory.
@racketmod[planet #,(this-package-version-symbol)
(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"
]
This program is in a language that has been enriched with
Javascript-specific functions. It can be partially evaluated in plain
Racket, but evaluation will halt at the call to @racket[image-url]
because @racket[image-url] constructs a image DOM element and needs to
run in an Javascript context.
Once the program is saved, create a new file called @filepath{run.rkt} in the same working directory with the
following contents:
@racketmod[racket
(require #,(racketmodname/this-package main))
(run-in-browser "test.rkt")
]
When this program is executed, @racket[run-in-browser] will take @filepath{test.rkt} and
translate it to run on the browser; a temporary web-server will opened
and your browser's window will open with the running program.
Finally, you can create zip packages by using @racket[create-zip-package]. For
example, modify @filepath{run.rkt} to be:
@racketmod[racket
(require #,(this-package-version-symbol))
(create-zip-package "test.rkt" "test.zip")
]
A slightly more substantial example is an animation using a built-in
functional event-driven programming library.
@racketmod[planet #,(this-package-version-symbol)
@code:comment{falling.ball.rkt}
@code:comment{Simple falling ball example. A red ball falls down the screen}
@code:comment{until hitting the bottom.}
(define-struct world (radius y))
@code:comment{The dimensions of the screen:}
(define WIDTH 320)
(define HEIGHT 480)
@code:comment{The radius of the red circle.}
(define RADIUS 15)
@code:comment{The world is the distance from the top of the screen.}
(define INITIAL-WORLD (make-world RADIUS 0))
@code:comment{tick: world -> world}
@code:comment{Moves the ball down.}
(define (tick w)
(make-world RADIUS (+ (world-y w) 5)))
@code:comment{hits-floor?: world -> boolean}
@code:comment{Returns true when the distance reaches the screen height.}
(define (hits-floor? w)
(>= (world-y w) HEIGHT))
@code:comment{We have some simple test cases.}
(check-expect (hits-floor? (make-world RADIUS 0)) false)
(check-expect (hits-floor? (make-world RADIUS HEIGHT)) true)
@code:comment{render: world -> scene}
@code:comment{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)))
@code:comment{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))
]
Again, to run this in the browser, we use @racket[run-in-browser]:
@racketmod[racket
(require #,(racketmodname/this-package main))
(run-in-browser "falling-ball.rkt")
]
@section{Running @js-vm[]}
@defmodule/this-package[main]
@defproc[(run-in-browser [input-file path-string?]) void]{
Consumes the given program, translates it so it can run on the browser,
and brings up the default browser.
At the moment, @js-vm[] currently supports programs written in the
@racketmodname/this-package[lang/wescheme] and
@racketmodname/this-package[lang/base] languages; further development
on @js-vm[] will work toward supporting modules written in full
Racket. @racket[require] should work as long as the required modules,
too, are in the supported languages.
}
@defproc[(create-zip-package [input-file path-string?] [output-zip-file path-string?]) void]{
Consumes the given program, translates it so it can run on the browser,
and writes out a zip archive to the given path. If the output file already exists, overwrites it. This zip file can be unpacked and served on any standard
web server.
}
@section{WeScheme}
@defmodule/this-package[lang/wescheme]
The language here acts as a kind of ``Pretty Big'' language,
and is the language used when @racket[planet #,(this-package-version-symbol)] is
the module language.
It provides the bindings from
@racketmodname/this-package[lang/base],
@racketmodname/this-package[lang/posn],
@racketmodname/this-package[image/image],
@racketmodname/this-package[jsworld/jsworld], and
@racketmodname/this-package[check-expect/check-expect].
It also adds @racket[open-image-url] and @racket[js-big-bang]
as aliases for @racket[image-url]
and @racket[big-bang] respectively.
@section{Jsworld}
jsworld provides a world programming library that allows simple
animation and games, as well as reactive HTML graphical user
interfaces.
@defmodule/this-package[jsworld/jsworld]
@defproc[(big-bang (a-world world) (handlers handler) ...) world]{
Starts a reactive computation with @racket[big-bang].
The rest of the arguments hook into the reactive computation.
By default, the page that's displayed contains a rendering of the
world value. In the presence of an @racket[to-draw] or
@racket[to-draw-page] handler, @racket[big-bang] will show a
customized view.
The majority of the handlers register different stimuli that can
trigger changes to the world. One instance is @racket[on-tick], which
registers a function to update the world on a clock tick. }
When the @racket[big-bang] computation terminates through a
@racket[stop-when], the final world is returned as its value.
@defproc[(to-draw [hook (world -> scene)]) handler]{
Draws a scene onto the display. For simple applications,
@racket[to-draw] is sufficient to draw a scene onto the display.}
@defproc[(stop-when [stop? (world -> boolean)]) handler?]{
When the world should be stopped --- when @racket[stop?] applied to the world
produces @racket[true] --- then the @racket[big-bang] terminates.
The program:
@racketmod[planet #,(this-package-version-symbol)
(define (at-ten x)
(>= x 10))
(big-bang 0
(on-tick add1 1)
(stop-when at-ten))
]
counts up to ten and then stops.
}
@defproc[(on-tick [world-updater (world -> world)]
[delay number? 1/20]) handler?]{
Produces a handler that responds to clock ticks. By default,
every tick comes every @racket[1/20]'th of a second.}
@defproc[(on-key [world-updater (world key? -> world)]) handler?]{
Produces a handler that responds to key events.}
@defproc[(key=? [key1 key?] [key2 key?]) boolean?]{Produces true if @racket[key1] is equal to @racket[key2].}
@; As soon as we have this, we'll comment it.
@;
@;{@defproc[(on-button-click) handler?]{Produces a handler that responds to button click events.}}
@defproc[(to-draw-page [to-dom (world -> (DOM-sexp))]
[to-css (world -> (CSS-sexp))]) handler]{
One of the main handlers to @racket[big-bang] is @racket[to-draw-page],
which controls how the world is rendered on screen. The first
argument computes a rendering of the world as a DOM tree, and the
second argument computes that tree's styling. }
@subsection{Jsworld Types}
A @racket[dom-sexp] describes the structure of a web page:
@racketgrammar[dom-sexp (list dom-element dom-sexp ...)]
a @racket[css-sexp] describes the structure of a page's styling:
@racketgrammar[css-sexp (listof (cons (or dom-element string)
(listof attrib)))]
An @racket[attrib] is a:
@racketgrammar[attrib (list string string)]
Each of the @racket[dom-element]s can take in an optional attribute list to
assign to the new dom element; the common useful attribute is a key-value binding for an "id",
which can be used to identify an element in the css-drawing function.
Here are examples of a dom-expr and a css-sexp.
@racketblock[
(define a-dom-sexp (list (js-div '(("id" "main-div")))
(list (js-text "Hello world"))))
(define a-css-sexp (list (list "main-div"
(list "background" "white")
(list "font-size" "40px"))))
]
@subsection{HTML user interface constructors}
Here are the dom-element constructors.
@defproc[(js-div (attribs (listof attrib?) '())) dom-element?]{
Constructs a div element.}
@defproc[(js-p (attribs (listof attrib?) '())) dom-element?]{
Constructs a paragraph element.}
@defproc[(js-button (world-update-f (world -> world))
(attribs (listof attrib) '()))
dom-element]{
Constructs a button. When the button is pressed, the world is updated through @racket[world-update-f].
The following example counts how many times a button has been clicked.
@(racketmod planet #,(this-package-version-symbol)
(define (press w)
(add1 w))
(define (draw w)
(list (js-div)
(list (js-button press) (list (js-text "Press me")))
(list (js-text (format "Button presses: ~a" w)))))
(define (draw-css w)
'())
(big-bang 0
(to-draw-page draw draw-css)))
}
@; commenting out effectful button.
@;{
@defproc[(js-button! (world-update-f (world -> world))
(effect-f (world -> effect))
(attribs (listof attrib) '()))
dom-element]{
Constructs a button. When the button is pressed, the original world is updated,
and the original world is used to construct an effect.
}}
@defproc[(js-text (text string?)) dom-element]{Constructs regular text.}
@defproc[(js-input (type string)
(world-update-f (or/c (world string -> world)
(world boolean -> world)))
(attribs (listof attrib) '()))
dom-element]{
Creates an input form element. The types that are currently supported are:
@itemlist[@item{@racket["text"]}
@item{@racket["password"]}
@item{@racket["checkbox"]}]
When the user changes the content of the form element, the runtime
uses @racket[world-update-f] to update the world. If the
@racket[type] is either @racket["text"] or @racket["password"], then
the string value of the element will be passed as the second argument
to it. If @racket[type] is @racket["checkbox"], a boolean
representing the checked status of the element will be passed to it.
The example below has a single text input form element, which allows the user to enter
some value.
@(racketmod planet #,(this-package-version-symbol)
(define (refresh w form-val)
form-val)
(define input-node
(js-input "text" refresh '(("id" "myname"))))
(define (draw w)
(list (js-div)
(list (js-div) (list (js-text (format "I see: ~s~n" w))))
(list (js-div) (list input-node))))
(define (draw-css w)
'())
(big-bang ""
(to-draw-page draw draw-css))
)
The example below uses a checkbox to select among three elements:
@(racketmod planet #,(this-package-version-symbol)
(define (make-ingredient-checkbox-sexp ingredient)
(local [(define (on-check w v)
(cond
[v
(cons ingredient w)]
[else
(remove ingredient w)]))]
(list (js-div)
(list (js-text ingredient))
(list (js-input "checkbox"
on-check
`(("value" ,ingredient)))))))
(define c1 (make-ingredient-checkbox-sexp "mushrooms"))
(define c2 (make-ingredient-checkbox-sexp "green peppers"))
(define c3 (make-ingredient-checkbox-sexp "olives"))
(define (draw w)
(list (js-div)
c1
c2
c3
(list (js-text (format "The world is: ~s" w)))))
(define (draw-css w)
'())
(big-bang '()
(to-draw-page draw draw-css)))
}
@defproc[(js-img (url string) (attribs (listof attrib) '())) dom-element]{Creates an image element.
}
@defproc[(js-select (options (listof string?)) (world-update-f (world string -> world)) (attribs (listof attrib) '())) dom-element]
Constructs a select element with the given options. Whenever a new
option is selected, the @racket[world-update-f] function is called to
get the new world.
The example below has a select with five elements.
@(racketmod planet #,(this-package-version-symbol)
(define (select-house w an-option)
an-option)
(define a-select-element
(js-select (list ""
"Gryffindor"
"Hufflepuff"
"Ravenclaw"
"Slytherin")
select-house))
(define (draw w)
(list (js-div)
(list a-select-element)
(list (js-text (format "House: ~a" w)))))
(define (draw-css w)
'())
(big-bang ""
(to-draw-page draw draw-css))
)
@;; Effects section is currently commented out: we did not
@;; yet port this over from the old Moby system.
@;{
@subsection{Effects}
Effects allow world programs to apply side effects to the outside
world. These are used in conjunction with the effect (@racket[!]) version of the
stimulus handlers described above.
@defproc[(make-effect:none) effect]{No result when interpreted.}
@defproc[(make-effect:beep) effect]{Audible beep when interpreted. On an Android smartphone, uses the notification ringtone.}
@defproc[(make-effect:play-sound (a-sound sound)) effect]{Plays a sound from the given @racket[sound]. If the sound is already playing, then the sound continues to play.}
@defproc[(make-effect:stop-sound (a-sound sound)) effect]{Stops playing a sound from the given url.}
@defproc[(make-effect:pause-sound (a-sound sound)) effect]{Pauses a sound; if @racket[make-effect:play-sound] for the same sound is given later, play restarts from the point where it was paused.}
A @racket[sound] is a:
@racketgrammar[sound string
playlist]
@defproc[(make-effect:set-sound-volume (volume number)) effect]{Sets the sound volume; the number should be between 0 and 100.}
@defproc[(make-effect:raise-sound-volume) effect]{Raises the sound volume. If the volume's already at 100, has no effect.}
@defproc[(make-effect:lower-sound-volume) effect]{Lowers the sound volume. If the volume's set to 0, has no effect.}
@defproc[(make-effect:set-beep-volume (volume number)) effect]{Sets the sound volume of the beep; the number should be between 0 and 100. On an Android smartphone, uses the notification sound.}
@defproc[(make-effect:play-dtmf-tone (tone number)) effect]{On a smartphone, plays a DTMF tone, where @racket[tone] is between 0 and 15 inclusive.}
@defproc[(make-effect:set-wake-lock (flag number)) effect]{On a smartphone, sets the wake-lock flag to prevent the phone from sleeping. Low-level call.}
@defproc[(make-effect:release-wake-lock) effect]{On a smartphone, releases a wake-lock to allow the phone to go to sleep again.}
@defproc[(make-effect:send-sms (phone-number string) (message string)) effect]{Sends an SMS message.}
@; Commenting out the generate-random documentation
@;{@defproc[(make-effect:generate-random: (world-update-f (world number -> world))) effect]{When interpreted, generates a random number on the fly and uses @racket[world-update-f] to update the world.}}
@defproc[(make-effect:pick-playlist (world-update-f (world playlist -> world))) effect]{Brings up a playlist picker; when a playlist is selected, the world is updated using @racket[world-update-f] with the selected @racket[playlist] sound.}
}
@section{Images}
@defmodule/this-package[image/image]
The contents of this module need to run in a Javascript context.
This module provides functions for creating images. The design of the library is meant to
follow 2htdp/image.
@defproc[(image? [x any/c]) boolean?]{
Produces @racket[#t] if @racket[x] is an image, and @racket[#f] otherwise.}
@defproc[(image=? [x any/c] [y any/c]) boolean?]{
Produces @racket[#t] if @racket[x] is the same image as @racket[y].}
@defproc[(circle [radius nonnegative-real?] [style (one-of/c 'solid 'outline)] [color color?]) image?]{
Produces a circle image with the given radius, style, and color.
}
@defproc[(nw:rectangle [width number?] [height number?] [style (one-of/c 'solid 'outline)] [color color?]) image?]{Produces a rectangle whose pinhole is at the upper left corner.}
@defproc[(rectangle [width number?] [height number?] [style (one-of/c 'solid 'outline)] [color color?]) image?]{Produces a rectangle whose pinhole is at its center.}
@defproc[(triangle) image?]{Produces a triangle.}
@defproc[(ellipse) image?]{}
@defproc[(line) image?]{Creates a line.}
@defproc[(text [message string?] [size number?] [color color?]) image?]{Creates a text image.}
@defproc[(image-url [url string?]) image?]{Reads in the image at the provided url and produces an image of its contents.}
@defproc[(star) image?]{Creates a star image}
@defproc[(empty-scene [width number?] [height number?]) image?]{Produces an empty scene with a border.}
@defproc[(place-image [x number?] [y number?] [an-image image?] [background image?]) image?]{
Places @racket[an-image] on top of @racket[background] at the given
@racket[x], @racket[y] coordinate.}
@defproc[(overlay [img1 image?] [img2 image?] ...) image?]{}
@defproc[(overlay/xy [img1 image?] [x real?] [y real?] [img2 image?]) image?]{}
@defproc[(underlay [img1 image?] [img2 image?] ...) image?]{}
@defproc[(underlay/xy [img1 image?] [x real?] [y real?] [img2 image?]) image?]{}
@defproc[(rotate [degree real?] [img image?]) image?]{Rotates the given by the degree.}
@defproc[(scale [factor real?] [img image?]) image?]{Scales the image.}
@defproc[(scale/xy [x-factor real?] [y-factor real?] [img image?]) image?]{Scales the image by the given @racket[x-factor], @racket[y-factor].}
@defproc[(put-pinhole [img image?] [x real?] [y real?]) image?]{}
@defproc[(image-width [an-image image?]) number?]{Produces the width of an image.}
@defproc[(image-height [an-image image?]) number?]{Produces the height of an image.}
Colors can be specified either by an RGB color structure, or by string name. Both are described now.
@defproc[(make-color [red number?] [green number?] [blue number?]) color]{
Produces a color with the given RGB triplet.}
@defproc[(color-red [c color?]) number]{Selects the red part of the color.}
@defproc[(color-green [c color?]) number]{Selects the green part of the color.}
@defproc[(color-blue [c color?]) number]{Selects the blue part of the color.}
@subsection{Available colors}
Here is a complete list of the strings that @racket[image] will recognize as colors.
@(apply itemlist
(map (lambda (str) (item (racket #,(string-downcase str))))
'("ORANGE"
"RED"
"ORANGERED"
"TOMATO"
"DARKRED"
"RED"
"FIREBRICK"
"CRIMSON"
"DEEPPINK"
"MAROON"
"INDIAN RED"
"INDIANRED"
"MEDIUM VIOLET RED"
"MEDIUMVIOLETRED"
"VIOLET RED"
"VIOLETRED"
"LIGHTCORAL"
"HOTPINK"
"PALEVIOLETRED"
"LIGHTPINK"
"ROSYBROWN"
"PINK"
"ORCHID"
"LAVENDERBLUSH"
"SNOW"
"CHOCOLATE"
"SADDLEBROWN"
"BROWN"
"DARKORANGE"
"CORAL"
"SIENNA"
"ORANGE"
"SALMON"
"PERU"
"DARKGOLDENROD"
"GOLDENROD"
"SANDYBROWN"
"LIGHTSALMON"
"DARKSALMON"
"GOLD"
"YELLOW"
"OLIVE"
"BURLYWOOD"
"TAN"
"NAVAJOWHITE"
"PEACHPUFF"
"KHAKI"
"DARKKHAKI"
"MOCCASIN"
"WHEAT"
"BISQUE"
"PALEGOLDENROD"
"BLANCHEDALMOND"
"MEDIUM GOLDENROD"
"MEDIUMGOLDENROD"
"PAPAYAWHIP"
"MISTYROSE"
"LEMONCHIFFON"
"ANTIQUEWHITE"
"CORNSILK"
"LIGHTGOLDENRODYELLOW"
"OLDLACE"
"LINEN"
"LIGHTYELLOW"
"SEASHELL"
"BEIGE"
"FLORALWHITE"
"IVORY"
"GREEN"
"LAWNGREEN"
"CHARTREUSE"
"GREEN YELLOW"
"GREENYELLOW"
"YELLOW GREEN"
"YELLOWGREEN"
"MEDIUM FOREST GREEN"
"OLIVEDRAB"
"MEDIUMFORESTGREEN"
"DARK OLIVE GREEN"
"DARKOLIVEGREEN"
"DARKSEAGREEN"
"LIME"
"DARK GREEN"
"DARKGREEN"
"LIME GREEN"
"LIMEGREEN"
"FOREST GREEN"
"FORESTGREEN"
"SPRING GREEN"
"SPRINGGREEN"
"MEDIUM SPRING GREEN"
"MEDIUMSPRINGGREEN"
"SEA GREEN"
"SEAGREEN"
"MEDIUM SEA GREEN"
"MEDIUMSEAGREEN"
"AQUAMARINE"
"LIGHTGREEN"
"PALE GREEN"
"PALEGREEN"
"MEDIUM AQUAMARINE"
"MEDIUMAQUAMARINE"
"TURQUOISE"
"LIGHTSEAGREEN"
"MEDIUM TURQUOISE"
"MEDIUMTURQUOISE"
"HONEYDEW"
"MINTCREAM"
"ROYALBLUE"
"DODGERBLUE"
"DEEPSKYBLUE"
"CORNFLOWERBLUE"
"STEEL BLUE"
"STEELBLUE"
"LIGHTSKYBLUE"
"DARK TURQUOISE"
"DARKTURQUOISE"
"CYAN"
"AQUA"
"DARKCYAN"
"TEAL"
"SKY BLUE"
"SKYBLUE"
"CADET BLUE"
"CADETBLUE"
"DARK SLATE GRAY"
"DARKSLATEGRAY"
"LIGHTSLATEGRAY"
"SLATEGRAY"
"LIGHT STEEL BLUE"
"LIGHTSTEELBLUE"
"LIGHT BLUE"
"LIGHTBLUE"
"POWDERBLUE"
"PALETURQUOISE"
"LIGHTCYAN"
"ALICEBLUE"
"AZURE"
"MEDIUM BLUE"
"MEDIUMBLUE"
"DARKBLUE"
"MIDNIGHT BLUE"
"MIDNIGHTBLUE"
"NAVY"
"BLUE"
"INDIGO"
"BLUE VIOLET"
"BLUEVIOLET"
"MEDIUM SLATE BLUE"
"MEDIUMSLATEBLUE"
"SLATE BLUE"
"SLATEBLUE"
"PURPLE"
"DARK SLATE BLUE"
"DARKSLATEBLUE"
"DARKVIOLET"
"DARK ORCHID"
"DARKORCHID"
"MEDIUMPURPLE"
"CORNFLOWER BLUE"
"MEDIUM ORCHID"
"MEDIUMORCHID"
"MAGENTA"
"FUCHSIA"
"DARKMAGENTA"
"VIOLET"
"PLUM"
"LAVENDER"
"THISTLE"
"GHOSTWHITE"
"WHITE"
"WHITESMOKE"
"GAINSBORO"
"LIGHT GRAY"
"LIGHTGRAY"
"SILVER"
"GRAY"
"DARK GRAY"
"DARKGRAY"
"DIM GRAY"
"DIMGRAY"
"BLACK")))
@section{Implementing Javascript Modules}
Warning: the material in this section is unstable and likely to change.
@subsection{Module Implementation in Javascript}
@defmodule/this-package[lang/js-impl/js-impl]
This module allows the definition of modules whose implementations
are written in Javascript.
As an example, the following two files provide an implementation
of @racket[double] in Javascript:
@racketmod[planet #,(this-package-version-symbol js-impl)
(require-js "double.js")
(provide double)]
@verbatim{
// double.js
EXPORTS['double'] =
new types.PrimProc('double', 1, false, false, function(x) {
return jsnums.multiply(x, 2)});
}
Any module implemented with
@racketmodname/this-package[lang/js-impl/js-impl]
will provide bindings that require a Javascript context.
@subsection{Conditional Module Implmentation in javascript}
@defmodule/this-package[lang/js-impl/js-conditional]
Any module implemented with
@racketmodname/this-package[lang/js-conditional/js-conditional]
can run either in a Racket or Javascript context.
@include-section["ffi/ffi.scrbl"]
@section{Base language}
@defmodule/this-package[lang/base]
This provides the basic set of bindings for @js-vm[] programs.
These include most of the bindings
from @hyperlink["http://docs.racket-lang.org/htdp-langs/advanced.html"]{ASL}
and some from regular Racket, including:
@(let ([names '(
;#%module-begin
;#%datum
;#%app
;#%top-interaction
;#%top
define
define-struct
if
cond
else
case
quote
unquote
unquote-splicing
lambda
case-lambda
let
let*
letrec
letrec-values
local
quasiquote
begin
begin0
set!
and
or
when
unless
recur
require
for-syntax
define-for-syntax
begin-for-syntax
prefix-in
only-in
provide
planet
all-defined-out
all-from-out
except-out
rename-out
define-syntax
let/cc
with-continuation-mark
true
false
pi
e
empty
eof
null
shared
with-handlers
write
display
newline
current-print
current-continuation-marks
continuation-mark-set?
continuation-mark-set->list
for-each
;; make-thread-cell
make-struct-type
make-struct-field-accessor
make-struct-field-mutator
struct-type?
struct-constructor-procedure?
struct-predicate-procedure?
struct-accessor-procedure?
struct-mutator-procedure?
procedure-arity
procedure-arity-includes?
make-arity-at-least
arity-at-least?
arity-at-least-value
apply
values
call-with-values
compose
current-inexact-milliseconds
current-seconds
not
void
random
sleep
identity
raise
error
make-exn
make-exn:fail
make-exn:fail:contract
make-exn:fail:contract:arity
make-exn:fail:contract:variable
make-exn:fail:contract:divide-by-zero
exn-message
exn-continuation-marks
exn?
exn:fail?
exn:fail:contract?
exn:fail:contract:arity?
exn:fail:contract:variable?
exn:fail:contract:divide-by-zero?
*
-
+
=
=~
/
sub1
add1
<
>
<=
>=
abs
quotient
remainder
modulo
max
min
gcd
lcm
floor
ceiling
round
numerator
denominator
expt
exp
log
sin
cos
tan
asin
acos
atan
sinh
cosh