Live data from Hacker News

Stop writing lambda expressions in Python

treyhunner.com

51–60 of 202 posts

Re: Stop writing lambda expressions in Python

#52

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 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…

What do you mean by "not Scottish"?

Re: Stop writing lambda expressions in Python

#53
post #14
post #4

all i could think of is "stop writing python". it seems to me that a lot of these problems are fundamental problems with python. i continue to not understand why anybody likes python the language. the fact that creating a function with lambda versus the normal way is different is bonkers. for example, in f# (and other sane languages), the following are identical: let test1 = fun x -> x * x let test2 x = x * x both re…

One of the python motto's is "explicit is better than implicit". Not having to pattern-parse the structures makes programs much easier to read for some people (lke me). But the point is, even with f# syntax, most of the blog post would still apply (needless function calls, non-trivial functions, multiline-unpacking and so on) I do not agree with some of the premises of this post, but saying that changing lambda synta…

> I do not agree with some of the premises of this post, but saying that changing lambda syntax will somehow help is just not true.

i wasn't really suggesting changing the syntax would help (although the confusion here is more semantic than syntactic). i was pointing out that in other languages, like in f#, things are much more clear than in python. the section mentioning the name thing is still not clear to me (in python) in terms of what exactly the differences are, and that was my point. that exists a lot in python.

Re: Stop writing lambda expressions in Python

#54
post #52

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 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…

What do you mean by "not Scottish"?

It'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.

Re: Stop writing lambda expressions in Python

#55
post #32

Earlier quoted context omitted.

I'm not sure what you mean by the first half of your comment. Both def and lambda create functions, and quoting from the article "Lambda expressions are just a special syntax for making functions. They can only have one statement in them and they return the result of that statement automatically.". def binds it to a name at the same time, which is remembered in the object (which AFAIK isn't really used for anything e…

it's because i am not that deeply familiar with python and the article is not clear itself on this. what is he complaining about then if they are identical in what's returned? is it simply because the REPL returns instead of the function name? why does the REPL do this? are they different in some subtle way? the point was in something like f#, lambda creates a function which can then be bound to a name if you want. i…

> is it simply because the REPL returns instead of the function name? why does the REPL do this?

Because lambdas don't have function names.

Re: Stop writing lambda expressions in Python

#57

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 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…

I 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/...

* Detecting if a number is a perfect square as a one-line lambda: https://github.com/ubernostrum/interviewer-hell/blob/master/...

Re: Stop writing lambda expressions in Python

#58

Earlier quoted context omitted.

Amen, brother. I'm not proficient in Python, but from my (admittedly, limited) experience with it, it feels like programming with a straightjacket on.

It is, and that's the point. The Python community coined TOOWTDI (there's only one way to do it) in response to Perl's "There's more than one way to do it". What that way is seems to be "what even the most clueless programmer could reasonably understand". This to the point where even the adoption of a concept as common as assignment expressions was met with a community shitstorm. It seems like a language designed for…

To be honest, I feel like Python's philosophy makes it easier to focus on the "craft" of programming; instead of worrying about small details like how to iterate through a collection, I'm able to just do it the boring-but-effective Pythonic way and move on to higher-level details of the program. So I guess I'm not strictly disagreeing with you, but I think the craft of programming is about far more than just how your code looks, and I find Python to be excellent for pursuing those other areas of craftsmanship.

Re: Stop writing lambda expressions in Python

#59
post #52

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 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…

What do you mean by "not Scottish"?

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!

Re: Stop writing lambda expressions in Python

#60

Earlier quoted context omitted.

In F#, can you ask a function object what its original name was? If so, what is the original name of "test1" and "test2" in your example? That's what python is doing and why the two are different. (I don't think a language should track that sort of thing, but that's a different story).

i am not for sure what you mean by "original name". the value of each of those function definitions are: val test1 : x:int -> int val test2 : x:int -> int you call them the same way, and they have the same type. a caller has no knowledge of how they were defined because it isn't important. they're identical.

I mean in python, one can ask a function what it was originally defined as. Sounds like in F# one can not, so that's why there's a difference in python between "var x = lambda..." and "def y(): ..."; the latter knows it is named "y" and the former has no idea what its name is (so it is "lambda").
Post reply on HN