[Ur] Set / Update values within a structure

Nitin Surana nsurana at usc.edu
Fri Nov 10 17:53:13 EST 2017


Hi Adam

I tried to create a sample from what I understand about your suggestion,
but of course I got it wrong.
Following is the code (which doesn't compile), which would demonstrate what
I'm trying to do (look for 4 forward slashes ////)

fun debugMe a =
        alert a;
        ////can't read from source n here, because it's defined within
main(), below doesn't compile
        fnn <- get n;
        fnn()

structure AB = Mymaths.Make(struct
                               val callback = debugMe
                           end)

fun main()=
  n <- source Nil;
  lss <- source Nil;
let
    fun callMe () =
        x <- AB.simple "test";
        debug x

    fun anotherCallback()
        //iterate over source lss and do something

in
    //Some code to change the callback debugMe to anotherCallback() but what ?!
    set n anotherCallback   ////this doesn't work
    return <xml>
        <body>
            <h1> Sample </h1>
            <button value="Click Me" onclick={fn _ => callMe()}></button>
        </body>
        </xml>
end

Thanks


On Fri, Nov 10, 2017 at 1:45 PM, Adam Chlipala <adamc at csail.mit.edu> wrote:

> You can register a callback that, when called, reads another callback out
> of a [source] and calls it.  Is that sufficient?
> On 11/10/2017 04:19 PM, Nitin Surana wrote:
>
> Hi Adam
>
> 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.
> 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.
>
> Also, is `ref` not supported in urweb ?
>
> Thanks
>
> On Fri, Nov 10, 2017 at 4:48 AM, Adam Chlipala <adamc at csail.mit.edu>
> wrote:
>
>> On 11/09/2017 10:42 PM, Harshita Kasera wrote:
>>
>> What I ultimately want to achieve is to be able to change the callback
>> function *debugMe* at a later point of time. Is it possible to set or
>> update values within a structure at a later point of time?
>>
>>
>> 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.
>>
>
>
> _______________________________________________
> Ur mailing list
> Ur at impredicative.com
> 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=
>
>


-- 
Regards
Nitin Surana
MS Computer Science
323-690-6529
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.impredicative.com/pipermail/ur/attachments/20171110/549f6259/attachment-0001.html>


More information about the Ur mailing list