#103 Preserving match failure info

feature_request
closed-fixed
4
2014-08-28
2005-06-01
No

At
http://www.eros-os.org/pipermail/e-lang/2004-May/009828.html
Kevin Reid writes:

Kevin Reid <kpreid at attglobal.net> wrote:

> It would be nice if map-pattern expansion preserved
subpattern match
> 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

Further thoughts:

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 ??
and =~~.

The expansion of a map-pattern (or quasi-pattern) would
then preserve
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)]) :=
__makeMap.fromPairs(__makeList.run(__makeList.run("a",
42.0)))

# problem: <ClassCastException: Must be an EInt: class
java.lang.Double(42.0)>

Since nullOk[Exception] and boolean are disjoint, the
existing ? *could*
be extended to support this without breaking any
existing code. =~,
however, can't.

Discussion

  • Mark Samuel Miller

    Logged In: YES
    user_id=54168

    The experimental addition of "trinary-define" to Kernel-E
    gives us an adequate primitive for solving this problem, but
    we still need to modify all the expensions that currently
    expand to a match-bind expression to expand into a
    trinary-define instead

     
  • Mark Samuel Miller

    Logged In: YES
    user_id=54168

    See the thread beginning at
    http://www.eros-os.org/pipermail/e-lang/2005-August/010929.html

    ? def a := "foo"
    # value: "foo"

    ? interp.setExpand(true)
    ? def [b :int] := [a]
    # expansion: def [b :int] := __makeList.run(a)

    # problem: <ClassCastException: String doesn't coerce to an int>

    ? def ["" => b :int] := ["" => a]
    # expansion: def [b :int, :__Empty] :__Extract.get("") := \ #
    __makeMap.fromPairs(__makeList.run(__makeList.run("", a)))

    # problem: <ClassCastException: String doesn't coerce to an int>

    ? def ["a" => x :int] := ["a" => 42.0]
    # expansion: def [x :int, :__Empty] :__Extract.get("a") := \ #
    __makeMap.fromPairs(__makeList.run(__makeList.run("a", 42.0)))

    # problem: <ClassCastException: Must be an EInt: class
    java.lang.Double(42.0)>

     
  • Mark Samuel Miller

    • priority: 1 --> 4
    • status: open --> closed-fixed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks