fuzion icon indicating copy to clipboard operation
fuzion copied to clipboard

Syntax of field declaration confusing?

Open fridis opened this issue 3 years ago • 1 comments

When I was a little tired working on my FOSDEM'23 submission, I had problems understanding the following code (taken from a comment in Fuzion base library feature cache.fz:

fn () -> cache_key := () -> cache_key (sortedArrayOf [6,4,1,9])

I think the Fuzion grammar might be confusing here.

Are there any good possibilities to change the grammar to make this clearer, the options I see are using a keyword like var

var fn () -> cache_key := () -> cache_key (sortedArrayOf [6,4,1,9])      # *** currently not allowed ***

or requiring the type to have no spaces

fn ()->cache_key := () -> cache_key (sortedArrayOf [6,4,1,9])

or putting the type in (/):

fn (() -> cache_key) := () -> cache_key (sortedArrayOf [6,4,1,9])      # *** currently not allowed ***

or permitting type inference for lambdas without arguments

fn := () -> cache_key (sortedArrayOf [6,4,1,9])      # *** currently not allowed ***

or, in general, permitting explicit types in lambdas

add := (a,b i32) -> a+b      # *** currently not allowed ***

fridis avatar Dec 12 '22 09:12 fridis

I kind of prefer this variant here:

fn Function cache_key := () -> cache_key (sortedArrayOf [6,4,1,9])

maxteufel avatar Dec 12 '22 10:12 maxteufel