Python Forum
an error --> a wanted feature
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
an error --> a wanted feature
#9
(Nov-23-2017, 09:18 AM)wavic Wrote: Well, you can rewrite __mul__ method to do whatever you want  Smile That is a feature of Python I really love!

lots of languages have this capability.  the Pike language has it.  i've read about it in other languages.  details, like the names of function will vary.
 
(Nov-23-2017, 04:51 PM)micseydel Wrote: @wavic, you can't have it cause an assignment to the RHS.

this was about assignment to the LHS, where sin(x) or __mul__(x,x) or x*x would be.  the idea was that the sin() function would handle this by handling an assigned-to case (i don't remember how that was detected) by doing a reverse function and assigning to it's argument.  Python could not easily do this, but that other language could because references were passed in all function call cases, even for types like int and float.  so it could assign to any argument as readily as Python can replace an element of a list.  for the multiply case, it would need to also detect that the two arguments were the same variable (not just the same value) and assign the square root of the assigned value, making the function/operation operate in reverse.  if they were not the same ... think about how you would handle x*y = z.

for Python this would be limited to not being able to assign to arguments.  but for certain things it might make more sense to get a more important value that way.  for any device that would be operated on primarily with one value (with a tuple in rare more complex cases). this could make sense for.  but it can also be argued that all cases can be handled by regular function calls, so it is unnecessary.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
an error --> a wanted feature - by Skaperen - Nov-21-2017, 05:03 AM
RE: an error --> a wanted feature - by heiner55 - Nov-22-2017, 04:32 PM
RE: an error --> a wanted feature - by Skaperen - Nov-23-2017, 03:04 AM
RE: an error --> a wanted feature - by micseydel - Nov-22-2017, 04:46 PM
RE: an error --> a wanted feature - by heiner55 - Nov-22-2017, 04:56 PM
RE: an error --> a wanted feature - by heiner55 - Nov-23-2017, 06:19 AM
RE: an error --> a wanted feature - by wavic - Nov-23-2017, 09:18 AM
RE: an error --> a wanted feature - by Skaperen - Nov-24-2017, 01:43 AM
RE: an error --> a wanted feature - by micseydel - Nov-23-2017, 04:51 PM
RE: an error --> a wanted feature - by nilamo - Jan-04-2018, 07:19 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020