[eeps] EEP 049: Value-Based Error Handling Mechanisms

Fred Hebert mononcqc@REDACTED
Thu Oct 29 15:18:47 CET 2020


Quick update to mention I've managed to set things up in a way where only
rewrites using case expressions could be used to make things work (assuming
tokenizer support for the other constructs):
https://gist.github.com/ferd/2f1134fd88615354fbf89c068216b259

I guess the question I have there is whether we feel this is acceptable, or
way too risky when it comes to constructs such as parse transforms which
work with the AST. It feels like this is a change that causes "minimal
displacement" but ends up being a much larger burden down the road when
people writing tools that work on Erlang code and abstract representations
have to be aware of these translations and subtle variations in order to
maintain user-intended semantics intact. Would it make sense to look at a
much deeper integration introducing new forms all the way to core erlang
(which could likely ignore begin ... else ... end and rewrite with case
expressions there)?

EEPs tend to come with a reference implementation so I'm starting to look
at ways I can feasibly pull this off on my own.

On Fri, Oct 23, 2020 at 9:57 AM Fred Hebert <mononcqc@REDACTED> wrote:

> On Fri, Oct 23, 2020 at 7:32 AM Björn Gustavsson <bjorn@REDACTED> wrote:
>
>>
>> We have handled the addition of new keywords in the past by having an
>> option to disable them (keeping the new keywords as atoms). That we
>> will allow the compilation of old code that uses the keyword as an
>> atom. (We did that when we introduced try/catch.)
>>
>
> Sounds good to me.
>
> I'd be fine speccing the addition of an 'else-style' keyword for begin
> ... end. A funny thing to consider is that if we add 'else', people will
> be really confused about why begin ... end has it but not if ... end. I
> figure this is out of scope for this specific RFC, but worth pointing out
> regardless.
>
> I'll try to find slack time over the next week or two to edit EEP-49,
> including the quoted workaround and possibly some additional research. But
> to do a tl:dr;, this is heading for:
>
>    - begin ... end with an optional begin ... else ... end variant
>    - The "unwrap expression" is replaced by a "match or return" mechanism.
>    - since there is no longer any unwrapping we can switch form <~ to <-
>    as an operator and keep rather familiar semantics
>    - the else keyword (or anything else that takes its place) would
>    require compiler options that specify using it as an atom to allow
>    compilation of older modules which do not use the construct and rely on the
>    same keyword.
>
> I'm gonna have to look into whether this can still be safely emulated with
> simple case expression being shifted around or if it requires fancier a
> lower-level rewrite. I doubt it can be that easy to do because we have to
> intersperse non-conditional code in there and a goto-like mechanism could
> make more sense (an option would also be to use a ref with a throw/catch,
> but I'd rather avoid the cost of generating a ref per block of
> conditionals). Anyway, while I look into this, that'll give time to get
> more potential feedback or information from the OTP team, which Kenneth has
> hinted at.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/eeps/attachments/20201029/04b83eb6/attachment.htm>


More information about the eeps mailing list