fuzion
fuzion copied to clipboard
Anonymous feature syntax `ref` vs `_` and missing `is`
The current syntax for an anonymous feature is like this (example taken from String.fz:
public type.concat(a, b String) String =>
ref : String
utf8 Sequence u8 => a.utf8 ++ b.utf8
The examples in PR #3100 show that this does not necessarily have to be a ref, and the ref will be created automatically via boxing, so we should find some other syntax, maybe using _ as follows
public type.concat(a, b String) String =>
_ : String
utf8 Sequence u8 => a.utf8 ++ b.utf8
Additionally, it would maybe be more consistent to require an is keyword
public type.concat(a, b String) String =>
_ : String is
utf8 Sequence u8 => a.utf8 ++ b.utf8
I think the is definitely adds clarity. I remember being confused by the syntax when learning fuzion.
Example from PR #3100
this code in tests/catch_postcondition/catch_postcondition.fz
# alternative implementation of catch using anonymous feature
#
catch1(code_catch String->T) =>
(ref : handle_post T
redef try => code_try()
redef catch(s String) => code_catch s).res
could become
# alternative implementation of catch using anonymous feature
#
catch1(code_catch String->T) =>
(_ : handle_post T
redef try => code_try()
redef catch(s String) => code_catch s).res