Kevin Reid writes:
Kevin Reid <kpreid at attglobal.net> wrote:
> It would be nice if map-pattern expansion preserved
> failures, and gave informative exceptions when the
domain of the map
> doesn't match:
> ? def [b :int] := [a]
> # problem: <ClassCastException: String doesn't coerce
to an int>
> ? def ["" => b :int] := ["" => a]
> # problem: such-that expression was false
The underlying problem here is that ? and =~ (which are
used in the
expansion of map-patterns and quasi-patterns) do not
allow specifying or
retrieving the exception.
One solution: alternate (or replacement) versions of ?
and =~ which use,
instead of boolean, nullOk[Exception] (as is returned by
Ref.optProblem/1). For the purposes of this example,
I'll call them ??
The expansion of a map-pattern (or quasi-pattern) would
pattern match failure exceptions:
? def ["a" => x :int] := ["a" => 42.0]
# expansion: def m_11 ?? (m_11.optExtract("a") =~~ [x
:int, m_9 ?
__equalizer.sameEver(m_9.size(), 0)]) :=
# problem: <ClassCastException: Must be an EInt: class
Since nullOk[Exception] and boolean are disjoint, the
existing ? *could*
be extended to support this without breaking any
existing code. =~,
Log in to post a comment.