[Ur] Proposed location literals to track caller's location in error msgs.

Gabriel Riba gabriel at xarxaire.com
Wed Jun 3 07:28:21 EDT 2015


I could add an "assert" function to lib/ur/top.ur

---

fun assert [a] (cond: bool) (msg: string) (loc: string) (x:a): a =

   if cond then x else error <xml>{[msg]} at {[loc]}</xml>

---

Usage:

---

fun safeDivBy [a] (_:eq a) (_:num a) (loc:string) (denom: a) (n: a): a =

   assert (denom <> zero) "precond: illegal divisor" loc <|

     n `divide` denom


fun main (): transaction page =

   let return <xml><body>{[result]}</body></xml>
   where
     val result = safeDivBy _LOC_ 0 5
   end

----------------

BTW, "let ... where ... end" is not documented in the reference manual.




More information about the Ur mailing list