Python Forum
if i had written my own language
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
if i had written my own language
#10
(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...
Reply


Messages In This Thread
if i had written my own language - by Skaperen - Apr-02-2017, 03:13 AM
RE: if i had written my own language - by metulburr - Apr-02-2017, 01:31 PM
RE: if i had written my own language - by wavic - Apr-02-2017, 01:49 PM
RE: if i had written my own language - by zivoni - Apr-02-2017, 02:41 PM
RE: if i had written my own language - by wavic - Apr-03-2017, 04:27 AM
RE: if i had written my own language - by Kebap - Apr-02-2017, 04:28 PM
RE: if i had written my own language - by Skaperen - Apr-03-2017, 01:55 AM
RE: if i had written my own language - by zivoni - Apr-03-2017, 07:40 AM
RE: if i had written my own language - by micseydel - Apr-03-2017, 03:36 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Is python an interpreted language or a compiled language? GouravDas 1 2,134 Jun-23-2020, 10:38 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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