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

Pages: 1-4041-

Functional programming in Python

Name: Anonymous 2008-04-27 5:16

I really like functional, it's what Python should have been to start with. Too bad Guido is taking the language in the complete wrong direction.
If I had the inclination, I'd make a fork of Python, get rid of the FIOC, classes, and all that other crap, make print etc. into real functions, and turn it into a real functional programming language.

Oh, and:
print(eval((lambda: '\n'.join(map(reduce(compose, (''.join, partial(starmap,
apply), partial(flip(zip), map(c, (compose(*map(itemgetter, map(int, oct(1))
)), itemgetter(2), compose(*map(itemgetter, map(int, repr(11))))))), repeat,
partial(partial, flip(apply)), c)), sorted(izip(imap(randrange, repeat(int(a
, 36))), chain(starmap(map, zip(map(partial(partial, flip(mod)), 'aa b i u '
's o spoiler code sup sub'.split()), repeat('[%s] [/%s]'.split()))), c('> 0'
'&2;3+'.partition(''.join(imap(compose(chr, partial(xor, 229)), starmap(add,
izip(*imap(partial(imap, ord), (a, b)))))))[::2])), repeat(reduce(add, imap(
partial(getitem, reduce(add, imap(chr, starmap(add, izip(chain(imap(compose(
partial(flip(sub), 108), ord), '+kquuv'), repeat(mod(reduce(add, map(ord, b)
), div(int(a, 36), 4197516)))), imap(ord, compose(partial(imap, itemgetter(0
)), groupby)(sorted(reduce(add,(a, b)))))))))), map(int, '%d' * 0x6 % tuple(
map(compose(partial(flip(sub), 42), ord), (reduce(add, map(reduce(compose, (
chr, partial(add, 0x2f), partial(apply, sub))), zip(*map(tuple, map(partial(
map, ord), (b, 'c Sti-')))))))))))))))))).func_code, (lambda n, g = dict(zip
('abc', ('bbcode', 'satori', lambda *c: c))): (map(g.update, ((__import__(m)
).__dict__ for m in n)), g)[1])('random functional operator itertools'.split
())))

Name: Anonymous 2008-04-27 5:46

>>1
make print etc. into real functions
This is coming in Python 3:
from __future__ import print_function

Name: Anonymous 2008-04-27 6:29

>>2
And that's the one good thing that's coming out of py3k. Guido's still hellbent on making OO the one and only way to do most things, so you have to write all sorts of lambda a: a.something() crud if you want to use functional constructs like map(). Sure, list comprehensions and generator expressions work sometimes, but what if you want to parallelize? With the traditional map(func, list) you can just replace the map. Not so with list comprehensions; the mapping has been moved behind the curtain.

Really, all I want is Haskell without all the excessive punctuation, Lisp without all the screwy function names... Python without all the OO-anvils weighing it down.

Name: Anonymous 2008-04-27 8:29

>>3
You mean function.lambda variables.a: a.something().

Haskell without all the excessive punctuation,
Example?

Lisp without all the screwy function names...
Example?

Python without all the OO-anvils weighing it down.
anvils.oo_anvils.weigh_down(languages.python)

Name: Anonymous 2008-04-27 8:29

>>1
FIOC is one of the best things to come out of Python.

Name: Anonymous 2008-04-27 8:50

>>4
>>Lisp without all the screwy function names...
>Example?
set! instead or !, lambda instead of \.

Name: Anonymous 2008-04-27 10:00

>>1
Perl6 will be much closer to Haskell than Python.
See the error of your ways and convert.

Name: Anonymous 2008-04-27 11:14

>>6
Terrible!

Name: Anonymous 2008-04-27 11:15

>>6
TWO WORDS: λ

Name: Anonymous 2008-04-27 11:15

(λ! foo '(+ x x))

Name: Anonymous 2008-04-27 11:30

>>8
(Terrible! a 2)

Name: Anonymous 2008-04-27 16:51

>>7
Who said anything about Perl? I want a functional language that looks like Python.

Name: Anonymous 2008-04-27 16:54

>>12
Try Haskell.

Name: Anonymous 2008-04-27 17:49

>>12
perl6 will have better support for functional programming than python, and will look more like python than haskell does.

Name: Anonymous 2008-04-27 19:11

>>14 Perls dead baby, Perls dead.

Name: Anonymous 2008-04-27 19:33

>>15
What about my baby?

Name: Anonymous 2008-04-27 20:07

>>16

PERL?

IS IT REALLY YOU?

THE GAME

Name: Anonymous 2008-04-27 20:52

>>14
One word, the forced $@[%#^&/$%~ of the code, thread over.

Name: Anonymous 2008-04-27 23:20

>>18
Two words, you have no idea what you're talking about, thread over.

Name: Anonymous 2008-04-27 23:58

>>19
What about my talking?

Name: Anonymous 2008-04-28 0:20

>>1
Just don't use class.

Name: Anonymous 2008-04-28 6:49

>>15

;_;

Name: Anonymous 2008-04-28 7:50

>>19
I know what I'm talking about: my preference for a clean-looking language with alphanumeric functions and variable names, with little excess punctuation. Putting $ and @ in front of all my variables isn't my idea of fun. To be honest I think Python has too much punctuation, but it's better than Perl, and it's certainly better than Haskell.

Name: Anonymous 2008-04-28 9:20

>>23
Two words, you still have no idea what you're talking about, thread over.

Name: Anonymous 2008-04-28 9:33

>>23
God damn, show me that horrid Haskell punctuation already.

Name: Anonymous 2008-04-28 9:52

>>23
foo x y = x+y

ZOMG I CAN'T READ IT FOR ALL THE ``ABSTRACT PUNCTUATION''

Name: Anonymous 2008-04-28 10:39

Functional as in useless.

Name: Anonymous 2008-04-28 13:22

>>27
HEHEHEHEHEHEHHEHE.

Yeah.

Name: Anonymous 2008-04-28 22:43

>>25

I'm talking about all the crap like <- -> => >> >>= !! \ ++ :: : . | ||, rather than functions with sensible names. If you want some examples in context, here's a bit from the official Haskell website:
the third function is known as "bind" but is written ">>="
(>>=) :: m a -> (a -> m b) -> m b

What the fuck, why not just call the goddamn thing "bind". Instead of three meaningless-looking punctuation characters, you'd be typing four actual letters, which you can actually fucking read and make sense of at first glance. If nothing else, you can at least infer then that it BINDS something.

Incidentally, this is why I like Python so much: typically it's extremely easy to jump into a program and get an idea of what's going on. Haskell coders love to take advantage of the fact that you can express practically everything without even typing any letters.

I've been continually told that xmonad is "really easy to understand" and that "you don't need to know any Haskell, you can just figure everything out by looking at it". These are actual statements made by xmonad users, mind.

    , ((modMask              , xK_b     ),
          modifyGap (\i n -> let x = (XMonad.defaultGaps conf ++ repeat (0,0,0,0)) !! i
                             in if n == x then (0,0,0,0) else x))


Or how about this:
    [((m .|. modMask, key), screenWorkspace sc >>= flip whenJust (windows . f))
        | (key, sc) <- zip [xK_w, xK_e, xK_r] [0..]
        , (f, m) <- [(W.view, 0), (W.shift, shiftMask)]]

Where does that .|. come from? I don't think I've ever encountered a penis operator before.

Haskell is full of shit like that, and if you somehow think it's even nearly as straightforward to read as typical Python (or even Perl) code, you're only fooling yourself.

Name: Anonymous 2008-04-29 0:31

is Guido a guido?

Name: Anonymous 2008-04-29 2:40

>>29
Think of learning about Haskell syntax like learning effective VI -- it has a steep learning curve but you'll be really productive once you've been through the learning process.

Name: Anonymous 2008-04-29 2:42

>>29
<- -> => \ :: | aren't even operators, they're syntax built into the language; i.e. you can't just replace them with functions. You might as well complain that Python uses = or : instead of words (also, def del len are not sensible names).
!! is an indexing operator. I don't see how [] is more sensibly named.
++ is list concatenation. Python uses +, which is much more misleading (also, since when is % a string formatting operator?).

>>= can be seen as "shift into"; that interpretation should be obvious to anyone who knows C/C++/Java/Perl/etc. Oh, I see Python uses << >> for bit shifts too! How unreadable. Why not shiftL shiftR like Haskell?
You could call >>= bind[/bind], but in typical (infix) usage that would make it twice as long. But hey, if it really bothers you that much, just say [code]bind m f = m >>= f and use bind.

Where does that .|. come from?
http://haskell.org/hoogle/?q=.%7C.

Haskell is full of shit like that, and if you somehow think it's even nearly as straightforward to read as typical Python (or even Perl) code, you're only fooling yourself.
In my experience a language is easier to read if you actually know it. Also, visually parsing Haskell is pretty trivial, especially compared to Perl. The main difficulty in understanding Haskell code lies in its high informational density IMHO: just three lines of code can encapsulate rather abstract and complex concepts. However, I don't think using more verbose identifiers instead of punctuation would help with that.

Here's your keybinding example with words instead of (most of the) punctuation:
concatMap
    (lambda (key, sc):
        concatMap
            (lambda (f, m):
                ((m `bitwiseXor` modMask, key),
                    screenWorkspace sc `bind` flip whenJust (windows `compose` f)))
            ((W.view, 0) `Cons` (W.shift, shiftMask) `Cons` Nil))
    (zip (xK_w `Cons` xK_e `Cons` xK_r `Cons` Nil) (enumFrom 0))

Somehow it doesn't look better to me.

Name: Anonymous 2008-04-29 3:10

(also, def del len are not sensible names)
I'd like to know what would be sensible. Would it be define, removeFromList, and length?

Name: Anonymous 2008-04-29 5:10

>>33
del does a lot more than ``removeFromList''.

Given the argument is coming from a Haskell-fag though, I think he'd prefer the functions to be somewhat less ``verbose''.

Name: Anonymous 2008-04-29 5:58

If people are putting this much effort into criticising a language then it's probably not a toy language anymore.

Name: Anonymous 2008-04-29 6:03

>>33
sub, delete and length.
>>34
Perl-fag, actually

Name: Anonymous 2008-04-29 6:16

hax my anus

Name: Anonymous 2008-04-29 7:27

del and len seem like fairly intuitive abbreviations to me; I was abbreviating "length" as "len" long before I got into Python. I think it would make more sense, though, to use func rather than def (as well as lambda -- many other languages use the same keyword for both anonymous and named functions; why can't Python?)

Name: Anonymous 2009-03-06 6:51

Now some of the   gods just sit   it out with   your project here   unless you paid   for it you   crawled out of   my C courses   now in College   on Eclipse with   CDT But then   I discovered regexes   and this followed.

Name: Anonymous 2009-03-06 6:51

NECRO POSTING IS FAGGOTS

Name: Sgt.Kabukiman䖉 2012-05-22 23:30

All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy

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