Closed subhod-i closed 1 year ago
I don't like it for two reasons:
let
doesn'tNote that this is not Haskell; evaluation order does matter, and so this could lead to ambiguities.
Can the let
keyword be used to assign a function to a variable in Sophia?
you have to read code bottom top in order to understand what is going on
This may not be a problem. You know the function you are calling is not somewhere in the smart contract but rather in the where clause that is attached to this caller function body.
Note that this is not Haskell; evaluation order does matter, and so this could lead to ambiguities.
Agreed
Can the let keyword be used to assign a function to a variable in Sophia?
let
cannot do it at the moment, but this is rather a missing feature. I would rather let let
introduce functions than implement where
. We are actually considering fixing that.
You know the function you are calling is not somewhere in the smart contract but rather in the where clause that is attached to this caller function body.
I have seen many abuses of it in Haskell and Purescript. In those languages this is especially confusing when people mix it with let
.
We could possibly consider limitations to how where
may be used, eg only on toplevel functions, only non-stateful functions, no nesting, etc. But that would complicate the language, while being even less useful. Also, if you need so many auxilary functions that let
is unreadable, then maybe you should create a namespace? We are planning to introduce nested namespaces in the upcoming future, so that would be my way to go.
I see your point. let
might work in this case. Looking forward to the namespace
feature. Feel free to close this issue!
The
Where
clause is self-explanatory in the functional programming paradigm. In Sophia, writing independent functions which are used only once in a method will improve the readability of the smart contract.