Is this a thing? Are Lambdas "Unpythonic?" or is the writer of the article totally off base?
Stop writing lambda expressions in Python
51–60 of 202 posts
Re: Stop writing lambda expressions in Python
#52I'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…
Re: Stop writing lambda expressions in Python
#53all 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 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
#54I'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"?
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
#55Earlier 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…
Because lambdas don't have function names.
Re: Stop writing lambda expressions in Python
#56Lambdas are in so many languages than it seems worth it to spend 10 minutes learning what they are.
Re: Stop writing lambda expressions in Python
#57I'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…
* 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
#58Earlier 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…
Re: Stop writing lambda expressions in Python
#59I'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"?
>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
#60Earlier 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.