Comments (5)
I am also searching for a more consistent syntax here. Some thoughts on := can be found in Fuzion design page on assignments.
from fuzion.
Thanks for the pointer.
from fuzion.
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.
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.
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 lambdasx -> 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
, notf(x i32) -> i32 is x*x
.
from fuzion.
Related Issues (20)
- lib: Composable Error Handling
- various issues parsing tuples
- reevaluate loop-_magic_ (automatic results of loops with e.g. until) HOT 1
- Example with infinite list results in `VerifyError: Expecting a stack map frame`
- use an ARM-runner to execute the tests
- Some numerical conversion don't check if the value fits into the target type HOT 2
- macOS: FAILED: f64: exp 1 = ℇ
- Detection of call to abstract no longer works
- segfault but check examples passes
- raise error on variable shadowing HOT 1
- java intrinsics: add functionality to cast something
- drop need for dash in first command-line arg
- Usage info `fz -h` is not pretty
- RAII (Resource Acquisition Is Initialization) in fuzion
- backend for MLIR
- merge workflows HOT 1
- macOS: action fails
- be/jvm: race condition seems to be back or still present
- get rid of global state
- unjustified "Block must end with a result expression"
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fuzion.