Hacker News new | ask | show | jobs
by gus_massa 619 days ago
If you oveload "+" to mean whatever-you-want, it's possible. Using bad python [1], it's something like:

  def sum(x,y):
    if is_number(x) and is_number(y):
      return x + y
    elif is_number(x) and is_percent(y):
      return x * (1 + y.value/100)
    else:
      raise fatal_error
I don't claim it's a good idea, but it's possible if the language allows operator overload.

[1] Sorry, my main current language is Racket, but I thought that python-like is easier to read for most people, in spite people that likes python can find like 10 error in 7 LOC.