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

Pages: 1-

Python: currying

Name: Anonymous 2010-04-29 9:40

Suppose we have an implementation of Python in which functions support currying. We write:


def f(x, y, z):
    print(x, y, z)

f(y=2)(1)(3)


What output will be generated?

Name: Anonymous 2010-04-29 10:10

>>1
This is a horrible idea.

Name: Anonymous 2010-04-29 10:15

from functools import partial

Name: sage 2010-04-29 10:21

>>3
PIG DISGUSTING

Name: Anonymous 2010-04-29 10:32

Why exactly is currying an important aspect of programming or algorithm creation?

Name: Anonymous 2010-04-29 10:36

>>5
It can be rather useful. If a language lets you implement currying yourself(preferably, within a couple of lines of code), it means it's worth using.

Name: Anonymous 2010-04-29 11:11

>>6
Yes, but why? and do what better with it?

Name: Anonymous 2010-04-29 11:59

>>7
Everything!

Name: Anonymous 2010-04-29 12:06

>>7
You can mask rotten meat with the spices

Name: Anonymous 2010-04-29 12:59

Why exactly is currying an important aspect of programming or algorithm creation?
Currying is just a form of method specialisation, and hope I don't have to tell you why method specialisation is useful.

Name: Anonymous 2010-04-29 14:10

>>1
I'd say the output'll be 2 1 3.
Is this a trick question?

Name: Anonymous 2010-04-29 14:28

>>1
The output would be Guido's still beating heart. You are now obligated to eat it (and do us all a favour.)

Name: Anonymous 2010-04-29 14:30

>>1
It should be a syntax error

Name: Anonymous 2010-04-29 14:43

>>1
It would output 2 and then shout about something involving not being able to use a function as a function.

Name: Captain Obvious 2010-04-29 15:46


1 2 3

And now back to /b/!

Name: Anonymous 2010-04-29 22:25

f(y=2)(1)(3)

What output will be generated?

the same output as if you do f(y=2,1,3).

Name: Anonymous 2010-04-30 13:08

If Python were a language where assignments counted as expressions (any procedural language worth its bits), this would assign y to 2 in the current scope and then call f(1 2 3).
Perl gets it right by using => for this kind of thing.

Name: Anonymous 2010-04-30 14:02

>>17
where assignments counted as expressions (any procedural language worth its bits)
THIS IS WHAT PERL PROGRAMMERS ACTUALLY BELIEVE

Seriously this is a horrible misfeature and only serves to make programs "clever" at the extreme expense of readability and maintainability. I'd wager that in any sane application (i.e. not deliberately obfuscated) using the value of an assignment in an expression is 90% of the time a typo.

Name: Anonymous 2010-04-30 14:13

>>18
Then you have lost.  Pay up.

Name: Anonymous 2010-04-30 14:19

>>17
the fuck???

˝=>˝ is the same as ˝,˝.

Name: Anonymous 2010-04-30 14:33

>>18
while ((c = getchar()) != EOF) is a common idiom in C, and it's useful to be able to do things like a = b = c = 0.
Those two are pretty much the only legitimate uses, though.

Name: Anonymous 2010-04-30 14:36

>>21
I agree with the first part, if (tmp = try_get_some_value()) is rather common idiom.

I want to note, however, that a = b = c = 0 is valid Python.

Name: Anonymous 2010-04-30 14:58

>>22
Yes, because it was specifically added as an exception to the usual syntax, when it could just elegantly be a consequence of the way things should work anyway. Python's artificial and useless distinctions between expressions and statements is a conceptual eyesore.

Name: Anonymous 2010-04-30 15:21

>>23
It's not an "exception", it's a part of the syntax.
http://docs.python.org/reference/simple_stmts.html#assignment-statements
Namely, this:
(target_list "=")+

If you're fighting with the language on intentional and rational parts of the syntax, maybe instead of bitching about it you should go use another language instead. Ruby might be more your thing, if you're into slow-as-fuck languages.

Name: Anonymous 2010-04-30 15:50

>>24
It's not an "exception", it's a part of the syntax.
He never said it wasn't a part of the syntax, but of course, if you could actually read, you would know that already.

If you're fighting with the language on intentional and rational parts of the syntax
His point was that it isn't rational, as it doesn't fit in with the rest of the syntax. No-one disputes that it was intentional.

Ruby might be more your thing, if you're into slow-as-fuck languages.
He already uses Python, so that's a given.

Name: Anonymous 2010-04-30 21:27

>>25
Penis

Name: Anonymous 2010-05-01 0:03

To all those complaining about Python:
http://en.wikipedia.org/wiki/Cognitive_dissonance

Name: Anonymous 2010-05-01 5:43

>>27
That can be applied to complaints about any language

Name: Anonymous 2010-05-01 13:56

>>28
Especially Malbolge

Name: Anonymous 2010-12-06 9:36

Back to /b/, ``GNAA Faggot''

Name: Anonymous 2011-01-31 20:14

<-- check em dubz

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