GithubHelp home page GithubHelp logo

=> vs. := about fuzion HOT 5 CLOSED

hkienle avatar hkienle commented on June 14, 2024
=> vs. :=

from fuzion.

Comments (5)

fridis avatar fridis commented on June 14, 2024

I am also searching for a more consistent syntax here. Some thoughts on := can be found in Fuzion design page on assignments.

from fuzion.

hkienle avatar hkienle commented on June 14, 2024

Thanks for the pointer.

from fuzion.

Achim63 avatar Achim63 commented on June 14, 2024

I'd prefer -> or =>, as modern programming fonts have nice ligatures for those (e.g. Cascadia Code or Fira Code), at least in Visual Studio Code, Sublime, BBedit and in multiple terminals (so that they are also used in the shell versions of vim, emacs etc.). Here's a compatibility list which might even give more ideas: https://github.com/tonsky/FiraCode#terminal-compatibility-list

from fuzion.

fridis avatar fridis commented on June 14, 2024

Thanks for the reference to FiraCode. Making the code look good in current editors is important.

My current ideas go a bit further. First, I would like to make the ( ) around the arguments in feature declarations optional. But then I probably need something to separate the result type from the arguments, i.e., instead of

add (a, b i32) i32 is a + b

one would write

add a, b i32 -> i32 is a + b

where -> serves as a separator between the arguments and the result type.

Then, I would like to use := for all assignments to fields, independent of type inference. So a field declaration with an explicit type would by

sum -> i32 := a + b

and with an inferred type, it would be

sum := a + b

Then, the syntax for a routine with type inference for the result could use '=>' as before, so the example from above

add a, b i32 -> i32 is a + b

could be written as

add a, b i32 => a + b

using type inference.

This is only slightly inconsistent: for fields, := is used in both cases, while for routines, is and => are used. I need this distinction since

add x, y i32 is

declares a constructor for a new product type add with elements x and y. An alternative syntax for a routine with explicit result type would be

add a, b i32 -> i32 => a + b

which would be more consistent, but for some reason I prefer using is here.

In summary, this might be the syntax:

sum -> i32 := a + b
sum := a + b
add a, b i32 -> i32 is a + b
add a, b i32 => a + b

or, using unicode chars as ligatures

sum → i32 ≔ a + b
sum ≔ a + b
add a, b i32 → i32 is a + b
add a, b i32 ⇒ a + b

Maybe, in a next step, the -> could be removed or made optional as well, resulting in

sum i32 := a + b
sum := a + b
add a, b i32 i32 is a + b
add a, b i32 => a + b

but this syntax might cause problems in the parser since it becomes more difficult to distinguish a feature declaration from a call. Also, this seems a bit hard for humans to parse as well, in particular for add with explicit result type.

from fuzion.

fridis avatar fridis commented on June 14, 2024

Closing this, the syntax of Fuzion has stabalized a bit by now:

  • := is used to declare a field and assign a value. It should no longer be used to mutate a value (even though the grammar still permits that (set x := y) and it happens in the base lib)
  • => is used to declare a routine with result type determined by type inference and also in a match-case.
  • -> is used in lambdas x -> f x
  • <- is used to assign a new value to a mutable field.
  • there is no need for a separator before a feature result type (f(x i32) i32 is x*x, not f(x i32) -> i32 is x*x.

from fuzion.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.