Posted to tcl by Stu at Mon Mar 25 08:18:35 GMT 2024view raw

  1. Notice how the return can be "dedented" without breaking the fucntion.
  2.  
  3. def current1 (self, pos=None):
  4. if pos is None:
  5. return self[self._pos]
  6. else:
  7. self._pos = pos
  8. return self.adjust()
  9.  
  10. def current2 (self, pos=None):
  11. if pos is None:
  12. return self[self._pos]
  13. else:
  14. self._pos = pos
  15. return self.adjust()
  16.  
  17. Reduced indenting:
  18.  
  19. def current3 (self, pos=None):
  20. return self[self._pos] if pos is None else (lambda y,x:x)(self.pos_set(pos), self.adjust())
  21.  
  22. def pos_set (self, pos):
  23. self._pos = pos