3 ms·
I'm sorry but this article is mostly not Scottish. Lambdas in Python are an old non-issue. They are what they are. I like 'em because you can do "stupid pyth
by carapace 8y ago
I'm sorry but this article is mostly not Scottish. Lambdas in Python are an old non-issue. They are what they are.
I like 'em because you can do "stupid python tricks" like Church numerals: https://en.wikipedia.org/wiki/Church_encoding https://en.wikipedia.org/wiki/Church_encoding
plus = lambda m: lambda n : lambda f: lambda x: m(f)(n(f)(x))
succ = lambda n: lambda f: lambda x: f(n(f)(x))
mult = lambda m: lambda n: lambda f: m(n(f))
exp = lambda m: lambda n: n(m)
c0 = lambda f: lambda x: x
c1 = lambda f: lambda x: f(x)
c2 = lambda f: lambda x: f(f(x))
c3 = lambda f: lambda x: f(f(f(x)))
c4 = plus(c1)(c3)
c5 = plus(c2)(c3)
c6 = plus(c1)(c5)
c7 = succ(c6)
c8 = succ(c7)
c9 = c3(succ)(c6)
c10 = mult(c2)(c5)
c11 = succ(c10)
c12 = mult(c3)(c4)
c64 = c3(c4)
c256 = exp(c2)(c8)
- jwilk 8y agoWhat do you mean by "not Scottish"?
- carapace 8y agoIt's a Mike Myers bit from SNL. He plays a Scotsman who insists, "If it's not Scottish it's crap!" I mean it as a self-deprecating way to decry the quality of the post without being too harsh. The author of the blog post had good intentions, but in my opinion he should have put it off for another decade or so, to gain perspective.
- damon_c 8y agohttps://en.wikipedia.org/wiki/No_true_Scotsman https://en.wikipedia.org/wiki/No_true_Scotsman >No true Scotsman or appeal to purity is an informal fallacy in which one attempts to protect a universal generalization from counterexamples by changing the definition in an ad hoc fashion to exclude the counterexample. edit: ok he didn't mean it that way!
- ubernostrum 8y agoI tend to abuse lambdas plus itertools/functools to write "obfuscated" Python for fun. For example... * FizzBuzz with no control-flow keywords: https://github.com/ubernostrum/interviewer-hell/blob/master/fizzbuzz/iterator.py https://github.com/ubernostrum/interviewer-hell/blob/master/... * Detecting if a number is a perfect square as a one-line lambda: https://github.com/ubernostrum/interviewer-hell/blob/master/squares/odds.py https://github.com/ubernostrum/interviewer-hell/blob/master/...
- carapace 8y agoAh, those are great. I can't find it now but some daredevil wrote a Lisp interpreter in a single Python expression. A work of art.