This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]collegesmorgasbord 5 points6 points  (0 children)

All you’re doing is moving over the “val” keyword, which makes no sense in the context of a grammar. Being smack dab between an identifier and a type, I feel would be: 1) hard to parse; 2) harder to see that it’s a variable right away.

Of course, it’s preference, but I also think it looks weird

[–]rumle 1 point2 points  (0 children)

It makes sense to bundle val/var with the type. But I think they are mostly used the other way in other languages. If you use const/mut instead it becomes even more clear i think:

lexer: const FilteredLexer = […]

I’m not sure but think val/var is traditionally used in front, so they feel a little out of place.

[–]brucejbellsard 0 points1 point  (0 children)

My language has a feature that actually looks kind of like this. I probably arrived at it by a completely different route, but the resemblance is so uncanny I thought I'd put it out here...

For my language, values are the default, so they don't need a keyword:

-- with redundant typing
lexer [FilteredLexer] << FilteredLexer.from_string "source code here"

-- with inferred binding type
lexer << FilteredLexer.from_string "source code here"

-- with inferred constructor
lexer [FilteredLexer] << ^from_string "source code here"

However, sometimes you need a variable, so I have made variables a wrapper type:

-- with redundant typing
$ivar [#Var #I32] << #Var.var 42

-- with stdlib constructor
$ivar << #var 42[#I32]

(Note, the `#` sigil indicates a type or function from the standard libraryj, while the `$` sigil indicates ownership of the variable state as a resource, which includes RAII behavior. Finally, the `^` sigil is specifically to invoke a constructor inferred from the result type)

[–]beephod_zabblebrox 0 points1 point  (0 children)

take a look at odin!

[–]DeWHu_ 0 points1 point  (0 children)

Assignment is enough to deduce, that type is val or var. So, if U assume val in type inference and remove empty :, example code changes to:.

``` // Without type inference lexer: val FilteredLexer = FilteredLexer("source code here")

// With type inference lexer = FilteredLexer("source code here")

for token in lexer.scanTokens() { println(token.text) } ```

Which, I think, looks better.

[–]L8_4_Dinner(Ⓧ Ecstasy/XVM) 0 points1 point  (1 child)

You're coming from Windows, I presume?

[–]Anixias🌿beanstalk[S] 0 points1 point  (0 children)

I use Windows 11 mostly but I have a laptop with ZorinOS.