Mercurial > urweb
annotate jslib/urweb.js @ 581:e955d50c389d
Double-bind works
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Tue, 30 Dec 2008 16:11:29 -0500 |
parents | bb8463c3b712 |
children | 66463006f893 |
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 } |