by kuni-toko-tachi · 11y ago · 0 comments
The criticisms that people had about Perl, such as that it langrage like line noise was unfortunate. Being able to tell whether something was a scalar, array, or hash by the character that preceded it was helpful.
Being able to slap a set of braces around code to create a closure was also much better than needing to do the same in a function like JavaScript.
Perl formed some much new ground. CPAN was the predecessor of npm, etc.
I'm just glad to be able to write functional code again through JavaScript, just like when I wrote Perl. I don't miss writing Java (or any static typed object oriented language) at all, and hope I never will again. I just hope that ES6 doesn't turn JavaScript engineers into object oriented programmers.
So what you end up writing is more akin to:
def multiplier_maker(a):
def temp(b):
return b * a
return temp
That is because Python allows you to declare a function anyware, even inside other functions. def counter():
counter.x += 1
return counter.x
counter.x = 0
counter()
> 1
counter()
> 2
Beware! singleton variables, mutable state, etc. >>> def counter():
... x = [ 1 ]
... def count():
... y = x[ 0 ]
... x[ 0 ] += 1
... return y
... return count
...
>>> count = counter()
>>> count()
1
>>> count()
2
>>> count()
3
>>> count()
4
>>>
>>> otherCount = counter()
>>> otherCount()
1
>>> otherCount()
2
>>> count()
5
>>> count()
6
>>> otherCount()
3
>>>