metaeducation / ren-c

Library for embedding a Rebol interpreter into C codebases
GNU Lesser General Public License v3.0
128 stars 27 forks source link

Should body results of loop constructs return the raised error? #1149

Open hostilefork opened 1 year ago

hostilefork commented 1 year ago

At one time the mechanics were such that body execution would be able to make it so that a raised error as a body result would come back as the result of the overall operation. For instance, here was the behavior of REDUCE-EACH:

>> ^ reduce-each x [1 + 2] [raise "foo"]]
== ~make error [
    type: ~null~
    id: ~null~
    message: "foo"
    near: [raise "foo" **]
    where: [raise do console]
    file: ~null~
    line: 1
]~

But conceptually, the suppression of promotion to failure should probably only be applied if it was the last iteration...otherwise a raised error might be missed. e.g. semantically we shouldn't run the 10 + 20 here and suppress the raised error:

>> ^ reduce-each x [1 + 2, 10 + 20] [if x = 3 [raise "foo"] else [x]]
** Error: foo

Returning a raised error as an "early return body result" may be a possibility, but seems dubious.

Hence the current behavior is that loops do not consider errors a viable final return result...but this raises some questions on how compositions like FOR-BOTH which generically META and UNMETA their arguments handle this.