Ur/Web Examples
Check-in [5a1c5eea69]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:- slight revisions to formatting
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:5a1c5eea69508bc38694b9ae5020168bb7aea975
User & Date: beyert 2015-02-23 01:41:28
Context
2015-02-23
03:42
- make jsMove more concise check-in: f85bb74c6b user: beyert tags: trunk
01:41
- slight revisions to formatting check-in: 5a1c5eea69 user: beyert tags: trunk
2015-02-21
08:15
- in JsMove, bring back usage of signals in setMouseEvents check-in: de3e6e7ecb user: beyert tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to iota/dataflow.ur.

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
val eq_production : eq production =
  mkEq (fn (x: production) (y: production) =>
     case (x, y) of (Produce, Produce) => True
                  | (Inhibit, Inhibit) => True
                  | _ => False)

val show_production : show production =
  mkShow (fn p : production => case p of Produce => "Produce"
                                       | Inhibit => "Inhibit")

fun invert (v: production) : production = case v of Produce => Inhibit
                                                  | Inhibit => Produce

(* loosely modeled after the periodic combinator in Netwire *)
fun periodic [a] (ms: int) (f: a -> a) (runOn: signal production)
  (outCell: source a) : transaction unit =







|
|







3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
val eq_production : eq production =
  mkEq (fn (x: production) (y: production) =>
     case (x, y) of (Produce, Produce) => True
                  | (Inhibit, Inhibit) => True
                  | _ => False)

val show_production : show production =
  mkShow (fn (p: production) => case p of Produce => "Produce"
                                        | Inhibit => "Inhibit")

fun invert (v: production) : production = case v of Produce => Inhibit
                                                  | Inhibit => Produce

(* loosely modeled after the periodic combinator in Netwire *)
fun periodic [a] (ms: int) (f: a -> a) (runOn: signal production)
  (outCell: source a) : transaction unit =

Changes to iota/iota.ur.

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
..
43
44
45
46
47
48
49
50
51
      (Lt, Gt) => periodic ms f runOn outCell
    | (Gt, Gt) => periodic ms f runOn outCell
     (* infinite loop is OK here, because this runs over time *)
    | (Eq, Gt) => periodic ms f runOn outCell
    |        _ => error <xml>invalid sequence defined</xml> end

fun main () =
  result <- source (0 : int);
  runOn <- source (Produce : production);

  return <xml><head>
    <title>Cycle numbers from {[show minNum]}
                           to {[show maxNum]}, every
                           {[show (timeInterval * unitMultiplier)]} ms:</title>
    </head>
    <body onload={spawn
................................................................................
      <dyn signal={cur <- signal result; return <xml>{[show cur]}</xml>}/>
      <p><button value="Pause Number Generation"
        onclick={fn _ => set runOn Inhibit}/></p>
      <p><button value="Resume Number Generation"
        onclick={fn _ => set runOn Produce}/></p>
      <p><button value="Toggle Pause"
        onclick={fn _ => runOn' <- get runOn; set runOn (invert runOn')}/></p>
    </body>
    </xml>







|
|







 







|
<
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
..
43
44
45
46
47
48
49
50

      (Lt, Gt) => periodic ms f runOn outCell
    | (Gt, Gt) => periodic ms f runOn outCell
     (* infinite loop is OK here, because this runs over time *)
    | (Eq, Gt) => periodic ms f runOn outCell
    |        _ => error <xml>invalid sequence defined</xml> end

fun main () =
  result <- source (0: int);
  runOn <- source (Produce: production);

  return <xml><head>
    <title>Cycle numbers from {[show minNum]}
                           to {[show maxNum]}, every
                           {[show (timeInterval * unitMultiplier)]} ms:</title>
    </head>
    <body onload={spawn
................................................................................
      <dyn signal={cur <- signal result; return <xml>{[show cur]}</xml>}/>
      <p><button value="Pause Number Generation"
        onclick={fn _ => set runOn Inhibit}/></p>
      <p><button value="Resume Number Generation"
        onclick={fn _ => set runOn Produce}/></p>
      <p><button value="Toggle Pause"
        onclick={fn _ => runOn' <- get runOn; set runOn (invert runOn')}/></p>
      </body></xml>

Changes to jsMove/jsMove.ur.

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

fun nullifyMouseEvents (touch: bool) : transaction unit =
  if touch then JsMoveJs.nullifyHandler "ontouchmove";
                JsMoveJs.nullifyHandler "ontouchstart"
  else JsMoveJs.nullifyHandler "onclick";
       JsMoveJs.nullifyHandler "onmousemove"

fun s [t] (a : source t) : (signal t) = signal a

fun setMouseEvents (touchOn: signal bool) (mouseOn: signal bool)
  (clickToMove: signal bool) (ptsrc: point') (minpt: point) (maxpt: point)
  : transaction unit =
  touchOn' <- current touchOn; mouseOn' <- current mouseOn;
  clickToMove' <- current clickToMove;
  let val f = (fn ptdest =>







|







39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

fun nullifyMouseEvents (touch: bool) : transaction unit =
  if touch then JsMoveJs.nullifyHandler "ontouchmove";
                JsMoveJs.nullifyHandler "ontouchstart"
  else JsMoveJs.nullifyHandler "onclick";
       JsMoveJs.nullifyHandler "onmousemove"

fun s [t] (a: source t) : signal t = signal a

fun setMouseEvents (touchOn: signal bool) (mouseOn: signal bool)
  (clickToMove: signal bool) (ptsrc: point') (minpt: point) (maxpt: point)
  : transaction unit =
  touchOn' <- current touchOn; mouseOn' <- current mouseOn;
  clickToMove' <- current clickToMove;
  let val f = (fn ptdest =>

Changes to pseudoRandomIota/pseudoRandomIota.ur.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

(* advances sequence, then sleeps for a certain number of ms *)
fun randomPeriodic (ms: int) (runOn: signal production) (outCell: source int)
  : transaction unit =
  periodicT ms (fn x => bind (rpc (prand x)) return) runOn outCell

fun main () : transaction page =
  result <- source (0 : int);
  runOn <- source (Produce : production);

  return <xml><head>
    <title>Generate random numbers, every
      {[show (timeInterval * unitMultiplier)]} ms:</title>
    </head>
    <body onload={let val ms = timeInterval * unitMultiplier
                  in spawn (randomPeriodic ms (signal runOn) result) end}>







|
|







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

(* advances sequence, then sleeps for a certain number of ms *)
fun randomPeriodic (ms: int) (runOn: signal production) (outCell: source int)
  : transaction unit =
  periodicT ms (fn x => bind (rpc (prand x)) return) runOn outCell

fun main () : transaction page =
  result <- source (0: int);
  runOn <- source (Produce: production);

  return <xml><head>
    <title>Generate random numbers, every
      {[show (timeInterval * unitMultiplier)]} ms:</title>
    </head>
    <body onload={let val ms = timeInterval * unitMultiplier
                  in spawn (randomPeriodic ms (signal runOn) result) end}>