`trap` example

14 views
Skip to first unread message

edA-qa mort-ora-y

unread,
Jul 22, 2017, 2:52:48 AM7/22/17
to Leaflang
Good progress on error handling. This example shows how `trap` can capture errors and values into one:

/*EXPECT(3too-high)*/
defn pine = (x) -> {
	has( x.error ) then trace( unopt(x.error).tag )
	has( x.value ) then trace( unopt(x.value) )
}

defn dpine = (a,b) -> {
	pine(a)
	pine(b)
}

defn cone = (x:integer) -> {
	x > 5 then fail string_tag("too-high")
	return x
}

dpine( trap cone(3), trap cone(7) )
Reply all
Reply to author
Forward
0 new messages