[Ur] Key-value store extension

Athene Noctua steenuil.owl at gmail.com
Mon Jan 29 10:43:10 EST 2018


Hi all,

I find it useful to have a module for storing global configuration
settings and the likes in my applications, using a single table with
key and value fields and a simple get/set interface. Unfortunately
this approach breaks the nice encapsulation properties you get with
Ur/Web tables, as there's no way to control which module can access
which key, and trying to generate the keys to avoid collisions would
likely be cumbersome and break through multiple versions of the same
application.

I was wondering if this was a useful enough feature to be added into
the language, and if I should bother trying to hack it into the
compiler, or if I should just stick with writing a functor and make a
key-val table for each module that needs it instead.

For example:

    key test : string

    fun set_test { Test = t } =
      storeSet test t

    val main =
      t <- storeGet test;
      return <xml>
        The value of test is {[Option.get "test" t]}.
        <form><textbox{#Test}/><submit action={set_test}/></form>
      </xml>

"key" is probably not a very good name, as adding it as a keyword it
would likely break a lot of existing code, but that's easy to change.

What do you think?

- Francesco



More information about the Ur mailing list