fuzion icon indicating copy to clipboard operation
fuzion copied to clipboard

Anonymous feature syntax `ref` vs `_` and missing `is`

Open fridis opened this issue 1 year ago • 2 comments

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

fridis avatar May 24 '24 17:05 fridis

I think the is definitely adds clarity. I remember being confused by the syntax when learning fuzion.

michaellilltokiwa avatar May 28 '24 13:05 michaellilltokiwa

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

simonvonhackewitz avatar Mar 20 '25 14:03 simonvonhackewitz