Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Also, a small prize (a "thank you!" from a stranger on the Internet i.e. me) to someone who can propose a good syntax for compound assignment with reversed subtraction:

I would do away with operator-assign operators and instead introduce a general syntax for updating a variable that can be used with any expression.

  x = _ + 1  # increment x
  x = 0 - _  # negate x
  output = sanitizeHtml(_)
  index = (_ + 1) % len(arr)


Thank you! Having a syntactical construct to reference the value of the lhs of the assignment's operator in its rhs without recalculating it is a pretty nifty trick: it works because there is only one lvalue on the lhs of an assignment, so there is no ambiguity to what it refers to. And it could even be extended to work with multivalued assignments, although less neatly. Amazing! Thank you again!




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: