Apr-03-2017, 07:40 AM
(Apr-03-2017, 01:55 AM)Skaperen Wrote: one feature my language would have is a way to add/extend/replace methods of standard type classes like bool, int, float, str, etc.
To some extent you can do it in python (unless you mean directly replacing str with your new str).
class sstr(str): _nums = ['zero', 'one', 'two', 'three', 'four', 'five'] def __add__(self, other): try: sel, oth = self.strip().lower(), other.strip().lower() return sstr(self._nums[self._nums.index(sel) + self._nums.index(oth)]) except: return sstr(str.__add__(self, other))
Output:>>> a = sstr("two")
>>> a
'two'
>>> a + "three"
'five'
>>> a += "two"
>>> a
'four'
>>> a += "three" # resut is out of "num" range
>>> a
'fourthree'
Indeed this is just a starting point, much more effort would be needed to make it as powerful as INTERCAL...