Should I rename this thread from "Partial Application" to something else?
Here are my responses:
Partial applicationThe "option 1" using lambda is just really defining a function that takes two args and calls out to another function. There is nothing special about it afaict:
- Code: Select all
>>> lam = lambda x: x
>>> lam
<function <lambda> at 0x3bbd30>
In any case, although I understand what partial applications give you, I don't find myself desiring them in day to day coding. However, sometimes that's misleading because if something is not available, you will tend to stop thinking about it in the practical interest of getting your work done. What I'm leading up to is this: Can you provide practical examples where partials make code cleaner?
Also, were you expecting to be able to pass a reference to the partial around like you can with a method?
TuplesMore and more I'm shying away from tuples > 2. Seems like I always regret using them in Python. For example, I might have a method that returns (a, b, c, d). One problem that can occur is a realization that the order is not logical and should be switched to (a, c, b, d). However, doing so will break every place the method is used, which is a deterrent. Another problem is adding info such as providing an 'e' after the 'd' as in (a, c, b, d, e). Although I suppose Cobra's current approach means the call sites will not be broken. However, it also means the call sites will not have the info like they would if you instead returned a dictionary or object and then examined it with `trace` or a debugger. Another minor problem is that tuple usage sometimes ends up encouraging code like this:
- Code: Select all
t = obj.foo
.bar(t[6])
# what is element 6?
I did add Pair<of TA, TB> to the Cobra std library recently. And it's only a matter of time until I add support for unpacking that.
My current belief is that if you want to return more than two values, then you should use a dictionary or an object which will avoid the problems described above.
Regarding the awkwardness of some of the .NET API (most of which is nice), we have several extension methods to the .NET class library including "dict.get(key, default)" which I enjoy over the awkward .tryGetValue. See:
StandardLibraryExtensionMethods/cobra/trunk/Source/Cobra.LangLambda SyntaxThe "do" keyword is also used for anonymous methods/closures. If there is not "=" after "do(a, b)" then there must be code for the anonymous method indented on the next line. Combined with the fact that commas are used to separate arguments to methods--the lambda could be inside a method call that takes more than one argument--I'm doubtful we can drop them.
However, I have been playing around with the idea that if an expression contained tilde-marked variables, it would be considered a lambda:
Note that this approach not only eliminates the "do" and the parens, but it also means you don't have to declare the variable twice (once as an argument and once when using it). There is the issue of what to do if you want to refer to the args out of order, such as reversing the comparison. Putting aside the fact that in this specific example, you could multiply by -1, I was thinking an extra tilde like so:
t.sort(~~b.compareTo(~a))
We also need inference of types on lambdas if the above is going to work. I have a local workspace that technically does this (the inference not the tildes), but unfortunately it reveals problems with method overload resolution, so it's not ready to be checked in yet.
Getting back to "~a" for lambdas, I'm strongly in favor of it until someone talks me out of it. I think it's easy to spot and makes the syntax cleaner.
"of" in genericsI will start a different thread for this.
Java enumsYes, Java enums do look pretty sweet. I haven't thought much about how to implement them in Cobra while still outputting something that is a true .NET enum. I guess you could say it's a low priority.
Named and option paramsDefinitely in the future, but probably behind things like:
-- Pick up extension methods declared in C#.
-- Support lambda expressions being interpreted as expression trees.
These issues come up when trying to leverage various recent .NET libraries.
Multi-assignmentI'm still in favor of the Python approach of complaining that there are too many values to unpack. A slice can be used when needed.
Other thingsI've started a programming koans project with Llewellyn Falco which I'll push out publicly later this month.
I'm looking to push out a Cobra 0.9 release soon which requires a bit more compiler work and some web site updates. Todd A has started on a new color theme.
<"IDE support" was here> - making a new thread