Jeepers, you perl guys make things so complicated...
Code:
from functools import partial cheers :) |
Quote:
And a lot of what I do is procedural too. But I did come to functional stuff from practice - things become more concise and better modularized. And IMO so much advertised OO comes as a subset of functional and functional looks more natural to me. Interestingly enough, there are languages in which not only functions are first class "citizens", but also types: http://www.aldor.org/ : Quote:
The funny thing WRT C++ is that the language itself is imperative (procedural), but its template engine is functional. |
Quote:
Furthermore, you have "from functools import partial" which Perl code doesn't have. So, where is the complexity in Perl code vs simplicity in Python code ? |
Quote:
Quote:
Quote:
Rewriting the entire function itself in order to accommodate partial callings? Or writing this fairly trivial function as it would be called normally, and then calling it from "partial" when partial execution is needed? Not to mention calling it explicitly identifying the parameter you desire to set, rather than having to "shift" through the parameters. Someone else coming along after the fact trying to understand and maintain this code is going to see more clearly what is going on in my example, as opposed to having to calculate what is going on in that function with all those shifts. |
BTW, I could have done:
Code:
for X in [1,2]: A good resource for info on functional programming in Python is here: http://www.amk.ca/python/writing/functional |
Quote:
Someone else coming along, if he/she knows the AST I'm talking about, which is: Code:
+ In the tree there is no named parameters, there is a path to walk, and I have expressed the path. You didn't answer my question asked using the example with two "C" functions I've written - one of them calculating a * b + c, the other - x * y + z - my Perl code does not pose such a question, and it's good IMO since the question is irrelevant, your Python code does pose such a question. If you have to modify the code to become (x * y + z) * u, you'll have to introduce an extra 'u' variable, which is in the same scope as already existing 'x', 'y', 'z', i.e. you have to make sure your newly introduced 'u' entity does not clash with the existing ones. This, of course, is not a big deal with such a small example, but it becomes a problem in real life - look at futile attempts to use namespaces/packages in C++, Java and even Perl itself if we stick to "traditional" OOP. "My" approach/code does not have this name collision problem _by construction_, i.e. the only name used ($result) is scoped and export/import is implemented anonymously, thus avoiding the problem altogether. The last, but not least. Your code is not Python as such - it's Python plus an external module. My code is pure Perl, i.e. I've used only the language. |
Quote:
|
Quote:
|
Quote:
But, of course, presence of such a module is useful. I do not know Python 'functools' implementation details, i.e. whether it poses performance penalty or not. And, at all, it was claimed that Python is a more modern language than Perl - I do not see a proof yet, and I haven't seen the definition of "modern". |
Let's check whether Python can do this (this is Perl):
Code:
my %hash; And more :-). |
Quote:
Quote:
Quote:
|
Quote:
|
Well, my information that Python did not support partial evaluation was apparently out of date. Still, I will venture another opinion, namely that Python does not support autovivification and that setdefault is something else entirely.
|
Quote:
Another unanswered piece - multidimensional array in my example - the "[3][5]" part. What about multidimensional arrays in Python nowadays ? And, after quick looking into http://python.net/crew/mwh/hacks/setdefault.html , it's not clear to me how many times I'll have to write 'setdefault' in case of my Code:
${$hash{foo}{bar}{doo}{dah}}[3][5] = 'boo'; If the "[3][5]" part is a problem, then Code:
$hash{foo}{bar}{doo}{dah} = 'doh'; |
Quote:
Code:
>>> d = dict() Code:
>>> class default_dict(dict): i think it also can be done using setdefault albeit a bit more effort, or does it? Code:
>>> class auto_dict(dict): |
All times are GMT -5. The time now is 06:43 AM. |