ElaraLang / elara-go

Interpreter for old Elara specification, written in Go
16 stars 1 forks source link

Possible Syntax Adjustment #1

Open bristermitten opened 4 years ago

bristermitten commented 4 years ago

This isn't anything fancy, just proposing a small tweak to function syntax

let print-hello = () => {
    print "Hello"
}

Would become

let print-hello = _ => {
    print "Hello"
}

And

let greet = (Person p) => {
    print "Hello " + p.name
}

Would become

let greet = Person p => {
    print "Hello " + p.name
}

Without parentheses

Just an idea, but it looks cleaner imo

oppsec commented 3 years ago

In my opinion, with parentheses looks better, and people are more familiar with the parentheses

bristermitten commented 3 years ago

In my opinion, with parentheses looks better, and people are more familiar with the parentheses

Perhaps. I think it's mainly personal preference.

On a similar note, what about this?

I think we should consider changing the function syntax significantly I've been doing some research into FP and pretty much every functional language has much more concise function declaration

let square x = x * x

in F# for example

meanwhile in elara it would be

let square = (Int x) => x * x

which obviously is pretty verbose

If hypothetically we were to borrow F#'s syntax, we'd have a more concise syntax, functions and variables would still be declared in the same way, and we wouldn't need the hacky let blah => blah anymore

Thoughts?

oppsec commented 3 years ago

I still think that with let square x = x * x it would be better, more verbose languages are less attractive to new programmers, from what I see.

bristermitten commented 3 years ago

Yeah I agree. As much as the current syntax is arguably clearer, the verbosity is going to be counter productive (especially considering that FP is all about small, repeatable functions)

Perhaps we could use the let square x = x * x for functions, and the current syntax for anonymous functions

Vshnv commented 3 years ago

How would the contract be defined for x in that example?

bristermitten commented 3 years ago

Well, in F# there's some pretty powerful type inference for parameters.

If Elara doesn't support that, we could do

let square Int x = x * x

perhaps

Eg

let add Int a, Int b = a + b
bristermitten commented 3 years ago

Or of course something like

let add a: Int, b: Int = a + b

But I think parameter type inference is definitely something we should consider

oppsec commented 3 years ago

Or of course something like

let add a: Int, b: Int = a + b

But I think parameter type inference is definitely something we should consider

I liked this way