Mercurial > urweb
annotate jslib/urweb.js @ 584:101eb0058136
Used an option as a source
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Thu, 01 Jan 2009 10:49:42 -0500 |
parents | 66463006f893 |
children | 35471f067980 |
rev | line source |
---|---|
adamc@580 | 1 function cons(v, ls) { |
adamc@580 | 2 return { n : ls, v : v }; |
adamc@580 | 3 } |
adamc@579 | 4 function callAll(ls) { |
adamc@579 | 5 for (; ls; ls = ls.next) |
adamc@579 | 6 ls.v(); |
adamc@579 | 7 } |
adamc@574 | 8 |
adamc@580 | 9 function sc(v) { |
adamc@580 | 10 return {v : v, h : null}; |
adamc@580 | 11 } |
adamc@580 | 12 function sv(s, v) { |
adamc@580 | 13 s.v = v; |
adamc@580 | 14 callAll(s.h); |
adamc@580 | 15 } |
adamc@579 | 16 |
adamc@580 | 17 function ss(s) { |
adamc@580 | 18 return s; |
adamc@580 | 19 } |
adamc@580 | 20 function sr(v) { |
adamc@580 | 21 return {v : v, h : null}; |
adamc@580 | 22 } |
adamc@580 | 23 function sb(x,y) { |
adamc@580 | 24 var z = y(x.v); |
adamc@580 | 25 var s = {v : z.v, h : null}; |
adamc@580 | 26 |
adamc@580 | 27 function reZ() { |
adamc@580 | 28 z.h = cons(function() { s.v = z.v; callAll(s.h); }, z.h); |
adamc@580 | 29 } |
adamc@580 | 30 |
adamc@580 | 31 x.h = cons(function() { z = y(x.v); reZ(); s.v = z.v; callAll(s.h); }, x.h); |
adamc@580 | 32 reZ(); |
adamc@580 | 33 |
adamc@580 | 34 return s; |
adamc@580 | 35 } |
adamc@571 | 36 |
adamc@571 | 37 function dyn(s) { |
adamc@571 | 38 var x = document.createElement("span"); |
adamc@571 | 39 x.innerHTML = s.v; |
adamc@571 | 40 document.body.appendChild(x); |
adamc@580 | 41 s.h = cons(function() { x.innerHTML = s.v }, s.h); |
adamc@571 | 42 } |
adamc@582 | 43 |
adamc@582 | 44 function ts(x) { return x.toString() } |
adamc@584 | 45 function pf() { alert("Pattern match failure") } |