News for hackers. Stuff that matters.
Re:Stop writing lambda expressions in Python by jjnoakes on Thursday September 27, 2018 @04:08PM (#18088096)
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).

Re:Stop writing lambda expressions in Python by nikofeyn on Thursday September 27, 2018 @04:17PM (#18088165)
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.
Re:Stop writing lambda expressions in Python by jjnoakes on Thursday September 27, 2018 @05:09PM (#18088705)
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").
Re:Stop writing lambda expressions in Python by yorwba on Thursday September 27, 2018 @04:35PM (#18088357)
> they're identical.

Does that mean that test1 == test2 will return true?

Personally, I have found it very useful for debugging that function objects in Python carry their name. That makes it much easier to find out where something is coming from.