comparison tests/jscomp.ur @ 975:8fe576c0bee9

Quoting JavaScript working
author Adam Chlipala <adamc@hcoop.net>
date Tue, 22 Sep 2009 15:12:09 -0400
parents b851675a2c3d
children
comparison
equal deleted inserted replaced
974:b851675a2c3d 975:8fe576c0bee9
4 fun fact n = 4 fun fact n =
5 case n of 5 case n of
6 0 => 1 6 0 => 1
7 | _ => n * fact (n - 1) 7 | _ => n * fact (n - 1)
8 8
9 datatype t =
10 A
11 | B of {C : int, D : float}
12 | E of t * t
13
14 fun render x =
15 case x of
16 A => "A"
17 | B {C = n1, D = n2} => "B(" ^ show n1 ^ "," ^ show n2 ^ ")"
18 | E (x, y) => "C(" ^ render x ^ "," ^ render y ^ ")"
19
9 fun main () = 20 fun main () =
10 s <- source ""; 21 s <- source "";
11 s' <- source ""; 22 s' <- source "";
12 f <- source (plus 1); 23 f <- source (plus 1);
13 f2 <- source fst; 24 f2 <- source fst;
14 r <- source {A = "x", B = "y"}; 25 r <- source {A = "x", B = "y"};
26 t <- source (E (A, B {C = 10, D = 1.23}));
27 ht <- source <xml>Nothing here yet.</xml>;
15 28
16 return <xml><body> 29 return <xml><body>
17 <ctextbox source={s}/> <ctextbox source={s'}/><br/><br/> 30 <ctextbox source={s}/> <ctextbox source={s'}/><br/><br/>
18 31
19 Function: <button value="+1" onclick={set f (plus 1)}/> 32 Function: <button value="+1" onclick={set f (plus 1)}/>
20 <button value="*3" onclick={set f (times 3)}/><br/><br/> 33 <button value="*3" onclick={set f (times 3)}/><br/><br/>
21 34
22 Function2: <button value="Fst" onclick={set f2 fst}/> 35 Function2: <button value="Fst" onclick={set f2 fst}/>
23 <button value="Snd" onclick={set f2 snd}/><br/><br/> 36 <button value="Snd" onclick={set f2 snd}/><br/><br/>
24 37
38 Both: <button value="*3,Snd" onclick={set f (times 3); set f2 snd}/><br/><br/>
39
25 <button value="Echo" onclick={s <- get s; alert s}/> 40 <button value="Echo" onclick={s <- get s; alert s}/>
41 <button value="Echo2" onclick={s <- get s; alert s; alert s}/>
26 <button value="-" onclick={s <- get s; alert (show (-(readError s : int)))}/> 42 <button value="-" onclick={s <- get s; alert (show (-(readError s : int)))}/>
27 <button value="+1" onclick={s <- get s; alert (show (readError s + 1))}/> 43 <button value="+1" onclick={s <- get s; alert (show (readError s + 1))}/>
28 <button value="*3" onclick={s <- get s; alert (show ((readError s) * 3))}/> 44 <button value="*3" onclick={s <- get s; alert (show ((readError s) * 3))}/>
29 <button value="!" onclick={s <- get s; alert (show (fact (readError s)))}/> 45 <button value="!" onclick={s <- get s; alert (show (fact (readError s)))}/>
30 <button value="f" onclick={s <- get s; f <- get f; alert (show (f (readError s)))}/> 46 <button value="f" onclick={s <- get s; f <- get f; alert (show (f (readError s)))}/>
33 | Some (n : int) => alert (show (n + 1))}/> 49 | Some (n : int) => alert (show (n + 1))}/>
34 50
35 <button value="f2" onclick={s <- get s; s' <- get s'; f2 <- get f2; alert (f2 s s')}/><br/><br/> 51 <button value="f2" onclick={s <- get s; s' <- get s'; f2 <- get f2; alert (f2 s s')}/><br/><br/>
36 52
37 <button value="A" onclick={r <- get r; alert r.A}/> 53 <button value="A" onclick={r <- get r; alert r.A}/>
38 <button value="B" onclick={r <- get r; alert r.B}/> 54 <button value="B" onclick={r <- get r; alert r.B}/><br/><br/>
55
56 <button value="render" onclick={t <- get t; alert (render t)}/><br/><br/>
57
58 <dyn signal={signal ht}/>
59 <button value="Set" onclick={s <- get s;
60 set ht <xml><button value="Dynamic!" onclick={alert s}/></xml>}/>
39 </body></xml> 61 </body></xml>