Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Why Python

Name: CrieS Raymond 2007-07-11 20:55 ID:zwAX6BRF

"[on reduce() being removed from python]So now reduce(). This is actually the one I've always hated most, because, apart from a few examples involving + or *, almost every time I see a reduce() call with a non-trivial function argument, I need to grab pen and paper to diagram what's actually being fed into that function before I understand what the reduce() is supposed to do. So in my mind, the applicability of reduce() is pretty much limited to associative operators, and in all other cases it's better to write out the accumulation loop explicitly."

ONE WORD, THE FORCED GUIDO VAN ROSSUM, THREAD OVER.

for the love of god, this guy is the dumbest programmer ever. even the most newbies programmers I know at my smalltalk class at university know how to use inject:into:, and would never write an acummulator loop correctly. Argue to any smalltalker that writing

|total|
aCollection do: [e| total := e method + total]
^total

is better and clearer than

^aCollection inject: 0 into: [e| total + e method]

and he'll kick you in the ass. And smalltalk isn't even a functional language!

Name: Anonymous 2007-07-11 20:56 ID:zwAX6BRF

oops, I meant

^aCollection inject: 0 into: [total e| total + e method]

Name: Anonymous 2007-07-12 1:47 ID:uAo2hRd4

Wait, wait, they removed reduce()?!

Name: Anonymous 2007-07-12 2:04 ID:ZIiscmt9

What does reduce do?

Name: Anonymous 2007-07-12 5:33 ID:Xq0GU2fK

>>4
Sounds like foldl/r to me, which is the most important operator in a functional language, considering that you can implement any other functional operation in terms of it.

Name: Anonymous 2007-07-12 5:39 ID:yyI2Uwbc

>>3
No

>>4
foldl, builtin

>>5
It's foldl. You can use reversed (another builtin) on the list for foldr (reversed is an iterator, it doesn't use any extra memory). There are also Python implementations of foldl, foldr, scanl and scanr in the popular functional module.

Name: Anonymous 2007-07-12 21:03 ID:CSESQMtj

Actually guido wanted to remove lambda from the language, but he couldn't. I'm talking about Python 3000, which is not supposed to be backwards compatible.
Anyway, guido says he hates reduce because it's too complex and has to write in paper what is doing every time he reads it.
I must admit understanding foldl, foldr, and the difference between them, took me a while; but it's no big deal, especially if  you can use either foldl or foldr.
Either way, my programming teacher at a course on oop, functional and logic programming (yeah, it's a bit of everything and yeah, it skips a lot of important stuff), taught it in 5 minutes, and everybody in the class understood how reduce worked. It's simple. You take three arguments, a list/collection/whatever, an initial value, and a function receiving two arguments, an element of the list, and a partial total. reduce applies this function to the list, what the function returns becomes the new partial total in the next application. The initial value is the starting partial total. After reduce has applied the function to all elements, it returns the total.

Nothing amazingly complex. It's easy to what

reduce(0, function(partialTotal,x){ return x.length + partialTotal;},aListOfStrings);

does.

or, let's say:

reduce(-1, function(partialTotal, x) { return max(x, partialTotal); }, aListOfNumbers);

or simply

reduce(-1, max, aListOfNumbers);



sums all the elements of the list.

Name: Anonymous 2007-07-12 21:49 ID:uAo2hRd4

why not max(aListOfNumbers).
then you don't get fucked up results when all your numbers are less than -1.

Name: Anonymous 2007-07-12 23:15 ID:4FlDUWvY

"foldl" is easier to understand than "reduce". You're folding the result of one application into the next.

Name: Anonymous 2007-07-12 23:18 ID:4FlDUWvY

>>8
How is max implemented?

>>7
Uh... since when did max() become summation? max(4,5) = 5, not 9.

Name: Anonymous 2007-07-15 20:07 ID:eS+GrL+4

>>10
sorry, I don't know how that line ended up there, in the middle of a rewrite.
All I meant is that is easy to see what
reduce(-1, max, aListOfNumbers); does. if all your numbers are bigger or equal to 0, you might want to use -1 to signal an empty list. Or not. Or maybe use a variant of reduce that does not take an initial value, and instead the first element of the list becomes the initial value. It returns an error on the empty list.

Name: Anonymous 2007-07-16 3:47 ID:rE2iJDwX

Negative-numbers-as-errors is retarded.

Name: Anonymous 2007-07-16 4:11 ID:nIBYLjGd

>>12 is retarded.  Most functions in C-like languages dealing with error-ridden environment (like reading from file, traversing directory structure etc) return positive number of something, thus negative is a convenient way to indicate an error.

Name: Anonymous 2007-07-16 4:21 ID:58uiOgf1

>>12
what would you prefer? seh? oh plz :)

Name: Anonymous 2007-07-16 4:39 ID:DOO4f85P

>>13,14
data Maybe = Just x
           | Nothing

Name: Anonymous 2007-07-16 5:04 ID:ZOne0JOx

ONE WORD, FORCED INDENTATION OF THE CODE, THREAD OVER!!!!

Name: Anonymous 2007-07-16 6:04 ID:CM5K7hNb

>>13,14
What 15 said. Or an equivalent.

Name: Anonymous 2007-07-16 6:39 ID:EEe9vE1k

The forced Guido van Rossum is both a good and a bad thing. It's good in that he managed to design one of the cleanliest, nicest general-purpose, multi-paradigm dynamic languages, if only starting from version 2.3. He also tries to maintain consistency and has quite good insight.

The bad thing is that he's a functional programming hating faggot, and as such Python isn't as FP-oriented as it should. It seems he almost trolls everyone by threatening to remove lambda, and enjoys seeing functional programmers suffer and be at his mercy.

Guido van Rossum: I be removing first-class functions cause I feel like it.
People: What the...!!!???
Guido van Rossum: Lol, j/k n00bs

Name: Anonymous 2007-07-16 6:47 ID:wWNwkK9L

he wanted to remove lamdba (he said he won't though). but first class functions were still available.

Name: Anonymous 2007-07-16 6:54 ID:cZwJ2u8N

The bad thing is that he's a functional programming hating faggot, and as such Python isn't as FP-oriented as it should. It seems he almost trolls everyone by threatening to remove lambda, and enjoys seeing functional programmers suffer and be at his mercy.
I wonder if this is the reason for some needlessly and unexpectedly destructive stdlib functions like list.sort(), or is there some other lame excuse like ``OMG OPTIMIZED''?

Name: Anonymous 2007-07-16 8:08 ID:Heaven

>>20
Unexpectedly destructive? The fucking documentation for .sort() says it's in-place. And as for needless, no, actually it's much needed, because if it were to duplicate the entire list you'd be wasting a lot of memory for no reason just to overwrite the old object 90% of the time. If that's too goddamn useful for you, try sorted(list), or GTFO my Python.

Name: Anonymous 2007-07-16 9:28 ID:Heaven

The bad thing is that he's a functional programming hating faggot, and as such Python isn't as FP-oriented as it should. It seems he almost trolls everyone by threatening to remove lambda, and enjoys seeing functional programmers suffer and be at his mercy.
lambda is just syntactic sugar anyway. you can implement it yourself with just the S and K combinators.

Name: Anonymous 2007-07-16 17:47 ID:ga0kb4ha

>>22
Yes. Python 3000 should be more like Unlambda.

Name: Anonymous 2007-07-16 19:16 ID:SDRC86hi

>>20
it's not unexpected, I guess. If I remember right (I don't program in python) most destructive functions in python don't return any values, so if you try to use them functionally, they don't work.
I prefer my functions, if destructive, functional, that is, I care for the value they return; just like in lisp, nreverse and the like. But I guess that would make it not "simple" enough, so I understand Guido's choice.
I still think he's a faggot for not understanding reduce though.

Name: Anonymous 2007-07-16 20:31 ID:cSg2KudF

>>24
Again, list.reverse() employs optimizations such that it doesn't waste a ton of memory duplicating a list when 90% of the time it would be used in a construct such as x = x.reverse() anyway. But just as there's x.sort() has sorted(x), you can easily use reversed(x) instead of x.reverse() if that's what you want. Either way, quit bashing python because it doesn't do what you want because you obviously haven't even bothered to learn about it.

Name: Anonymous 2007-07-16 20:38 ID:SDRC86hi

>>25
where did I bash python in the post you quoted? I just talked about personal preference. guido could have made x.reverse() return x itself, but that could be confusing, that's why he didn't, even if it would be convenient.
I personally never had to do x = x.reverse(), because when you program functionally, you rarely have to.

Name: Anonymous 2007-07-17 5:29 ID:p9Y70wL+

>>26
You should use reversed() anyways, it's far better than reverse, because it iterates over the sequence, without modifying it OR taking extra memory (save for a few bytes for the iterator object).

Name: Anonymous 2007-07-17 9:04 ID:Heaven

ONE WORD, THE FORCED FAIL OF STANDARD LIBRARY, THREAD OVER.

Name: Anonymous 2009-01-14 12:31

LISP

Name: Anonymous 2009-03-06 11:38

i is going   to be a   huge reason to   ever remove the   space between return   and changebuf but.

Name: Anonymous 2009-07-21 2:02

>>-1
July  ?

Name: Anonymous 2010-11-14 14:45

Name: Anonymous 2011-01-31 21:31

<-- check em dubz

Name: Anonymous 2011-02-03 1:32

Name: Anonymous 2011-02-03 6:50

Don't change these.
Name: Email:
Entire Thread Thread List