Motoko wishlist

I was thinking about the ability to use only those variables which have values known at compile time so in the example above we just substitute [PROPERTY_NAME] with .0 and compile to the exact same code.

I think we already have the ability to determine those as we can get errors like
non-static expression in library or module

@skilesare, your let-default is really just alternative syntax for switch. Redundancy like that ultimately makes a language harder to learn – somebody reading somebody else’s code needs to understand all the different syntaxes instead of just one canonical one.

@ZhenyUsenko, just define an accessor function:

func propertyName(tuple : Tuple) { tuple.0 };

But really, if you need to abstract like that, then clearly you shouldn’t be using tuples in the first place, but records.

1 Like

Understood…I just wish the switch syntax was a bit easier…or that we had a : ? style switch for the many places you need to do A or B. It just gets a bit wordy. do?{} is also one of those places that I’ve run in to confused looks. Some of the current syntax is just alien enough that people bounce off it and don’t come back until they really know the language.

let ?x = y defaults ?0;

or

let ?x = do?{y!} defaults ?0;

or

let ?x = switch(y){ case(?val)val; case(null) ?0;};

As far as learning goes, I’d say progression is a natural way to learn a language. In C# people learn if then before switch case. Learning at low complexity helps the user move to high complexity later. Now, most proficient dev’s don’t need this step up , but if we want the language to be accessible from proficiency = 0, I’d argue that it might be worth considering.

:eyes: experiment: pipe syntax with explicit linear placeholder by crusso Ā· Pull Request #3968 Ā· dfinity/motoko Ā· GitHub

4 Likes

Yesss. Give me that pipe syntactic sugar @claudio! :candy: