DEV Community

Discussion on: This is my dream language. Is it real?

Collapse
 
idanarye profile image
Idan Arye

I find it confusing that the types come before the name for variables and after the name for functions...

Collapse
 
thermatix profile image
Martin Becker • Edited

That looks like the return value, similar to how it's done in rust, what goes in the function is on the left, what comes out of the function is on the right.

Collapse
 
idanarye profile image
Idan Arye

In Rust the type is on the right in both variables and the return:

   name          type
    | name  type   |
    |  |    |      |
    V  V    V      V
fn foo(x: i32) -> i32

In C, the type is on the left for both the variables and the function (though one can argue that the arguments are also part of the function's type):

type name
 |   | type name
 |   |   |  |
 V   V   V  V
int foo(int x)

In this syntax the order is sometimes type...name and sometimes name...type:

name          type
 | type name   |
 |   |  |      |
 V   V  V      V
foo(Int x) -> Int
Thread Thread
 
thermatix profile image
Martin Becker

AH, yes you're right, I missed what you were specifically talking about.

Collapse
 
overcache profile image
overcache
   name          type
    | name  type   |
    |  |    |      |
    V  V    V      V
fn foo(x: i32) -> i32

did you make the illustration by hands? or there is some tools can do this

Collapse
 
idanarye profile image
Idan Arye

Just use a monospace font - any programming-oriented text editor will do.

Collapse
 
nektro profile image
Meghan (she/her)

The type is on the left when it's required and on the right when it's optional