<div dir="auto">The original question smells like a potential XY problem (<a href="http://xyproblem.info/">http://xyproblem.info/</a>). What's the actual goal? There is probably a functional pattern that solves the problem in a nicer way than the imperative mutation of a callback function.</div><div dir="auto"><br></div><div dir="auto">Nitin, if you specifically want to call a mutable Ur/Web callback from JavaScript, it's probably easiest to pass values you need (sources, callback functions, or anything else) through a custom JavaScript FFI function (below called passToJs) that you call from inside main. You can set global JavaScript variables or do whatever else from inside passToJs.</div><div dir="auto"><br></div><div dir="auto">val main =</div><div dir="auto"> src <- source (fn () => return ());</div><div dir="auto"> return <xml></div><div dir="auto"> <active code={passToJs (fn () => f <- get src; f ())}/></div><div dir="auto"> (* XML that may mutate src *)<br></div><div dir="auto"> </xml></div><div dir="auto"><br></div><div dir="auto">But I still suspect that this isn't the best solution to whatever the real problem is!</div><div dir="auto"><br></div><div dir="auto">Ziv</div><div dir="auto"><br></div><div><br><div class="gmail_quote"><div>On Fri, Nov 10, 2017 at 17:54 Nitin Surana <<a href="mailto:nsurana@usc.edu">nsurana@usc.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>Hi Adam<div><br></div><div>I tried to create a sample from what I understand about your suggestion, but of course I got it wrong. </div><div>Following is the code (which doesn't compile), which would demonstrate what I'm trying to do (look for 4 forward slashes ////)</div><div><br></div><div><pre style="background-color:rgb(43,43,43);color:rgb(169,183,198);font-family:Menlo;font-size:9pt">fun debugMe a =<br> alert a;<br> ////can't read from source n here, because it's defined within main(), below doesn't compile<br> fnn <- get n;<br> fnn()</pre></div></div><div><div><pre style="background-color:rgb(43,43,43);color:rgb(169,183,198);font-family:Menlo;font-size:9pt"><br><br>structure AB = Mymaths.Make(struct<br> val callback = debugMe<br> end)<br><br>fun main()=<br></pre></div></div><div><div><pre style="background-color:rgb(43,43,43);color:rgb(169,183,198);font-family:Menlo;font-size:9pt"> n <- source Nil;<br> lss <- source Nil;</pre></div></div><div><div><pre style="background-color:rgb(43,43,43);color:rgb(169,183,198);font-family:Menlo;font-size:9pt"><br>let<br> fun callMe () =<br> x <- AB.simple "test";<br> debug x<br><br></pre></div></div><div><div><pre style="background-color:rgb(43,43,43);color:rgb(169,183,198);font-family:Menlo;font-size:9pt"> fun anotherCallback()<br> //iterate over source lss and do something<br><br>in<br> //Some code to change the callback debugMe to anotherCallback() but what ?!<br> set n anotherCallback ////this doesn't work</pre></div></div><div><div><pre style="background-color:rgb(43,43,43);color:rgb(169,183,198);font-family:Menlo;font-size:9pt"><br> return <xml><br> <body><br> <h1> Sample </h1><br> <button value="Click Me" onclick={fn _ => callMe()}></button><br> </body><br> </xml><br>end</pre></div></div><div><div><pre style="background-color:rgb(43,43,43);color:rgb(169,183,198);font-family:Menlo;font-size:9pt"></pre></div><div>Thanks</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote"></div></div><div class="gmail_extra"><div class="gmail_quote">On Fri, Nov 10, 2017 at 1:45 PM, Adam Chlipala <span><<a href="mailto:adamc@csail.mit.edu" target="_blank">adamc@csail.mit.edu</a>></span> wrote:<br></div></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
<p>You can register a callback that, when called, reads another
callback out of a [source] and calls it. Is that sufficient?<br>
</p><span>
<div class="m_3646004311953126860m_3884067285525225605moz-cite-prefix">On 11/10/2017 04:19 PM, Nitin Surana
wrote:<br>
</div>
<blockquote type="cite">
<div>Hi Adam
<div><br>
</div>
<div>Thanks for responding. Is there any alternative to change
the callback ? I want to trigger a urweb function defined
within `let` block upon a javascript event. </div>
<div>Since, the function is within `let` block (because it needs
access to certain variables within the parent function), I'm
unable to use execF(...) from javascript.</div>
<div><br>
</div>
<div>Also, is `ref` not supported in urweb ?</div>
<div><br>
</div>
<div>Thanks</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Fri, Nov 10, 2017 at 4:48 AM, Adam
Chlipala <span><<a href="mailto:adamc@csail.mit.edu" target="_blank">adamc@csail.mit.edu</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF"><span>
<div class="m_3646004311953126860m_3884067285525225605m_5243511948070250283moz-cite-prefix">On
11/09/2017 10:42 PM, Harshita Kasera wrote:<br>
</div>
<blockquote type="cite">
<div><span style="font-size:12.8px"></span>
<div style="font-size:12.8px">
<div style="font-size:12.8px">What I ultimately
want to achieve is to be able to change the
callback function <i>debugMe</i> at a later
point of time. Is it possible to set or update
values within a structure at a later point of
time?</div>
</div>
</div>
</blockquote>
<br>
</span> No, module (structure) fields can't be modified at
runtime in Ur/Web or ML. Therefore, the module system is
not the right tool for runtime rewriting of callbacks.<br>
</div>
</blockquote>
</div>
</div>
</blockquote>
<br>
</span></div>
<br>_______________________________________________<br>
Ur mailing list<br>
<a href="mailto:Ur@impredicative.com" target="_blank">Ur@impredicative.com</a><br>
</blockquote></div></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__www.impredicative.com_cgi-2Dbin_mailman_listinfo_ur&d=DwIGaQ&c=clK7kQUTWtAVEOVIgvi0NU5BOUHhpN0H8p7CSfnc_gI&r=fRXDP9LYNqdFgci7lxN2fw&m=4BPlw-ffwmldYJ_nUfPoCMcCEtXDUqFj73lIc-B35lQ&s=SdXCyX5EL_W3lxWpCwUlkH65djIEQvhG4MnsKPjypKE&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__www.impredicative.com_cgi-2Dbin_mailman_listinfo_ur&d=DwIGaQ&c=clK7kQUTWtAVEOVIgvi0NU5BOUHhpN0H8p7CSfnc_gI&r=fRXDP9LYNqdFgci7lxN2fw&m=4BPlw-ffwmldYJ_nUfPoCMcCEtXDUqFj73lIc-B35lQ&s=SdXCyX5EL_W3lxWpCwUlkH65djIEQvhG4MnsKPjypKE&e=</a><br>
<br></blockquote></div></div><div class="gmail_extra"><br><br clear="all"><div><br></div>-- <br><div class="m_3646004311953126860gmail_signature" data-smartmail="gmail_signature"><div><div><div><div>Regards<div>Nitin Surana</div><div>MS Computer Science</div><div>323-690-6529</div><div><br></div></div></div></div></div></div>
</div>
_______________________________________________<br>
Ur mailing list<br>
<a href="mailto:Ur@impredicative.com" target="_blank">Ur@impredicative.com</a><br>
<a href="http://www.impredicative.com/cgi-bin/mailman/listinfo/ur" rel="noreferrer" target="_blank">http://www.impredicative.com/cgi-bin/mailman/listinfo/ur</a><br>
</blockquote></div></div>