![]() |
if i had written my own language - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: General (https://python-forum.io/forum-1.html) +--- Forum: News and Discussions (https://python-forum.io/forum-31.html) +--- Thread: if i had written my own language (/thread-2676.html) |
if i had written my own language - Skaperen - Apr-02-2017 if i had written my own language there are some things i would have done differently. can you guess what one of them is?
RE: if i had written my own language - ichabod801 - Apr-02-2017
RE: if i had written my own language - metulburr - Apr-02-2017 Then your language would be weird
RE: if i had written my own language - wavic - Apr-02-2017 Non-empty object is always True. RE: if i had written my own language - zivoni - Apr-02-2017 (Apr-02-2017, 01:49 PM)wavic Wrote: Non-empty object is always True. Not exactly, its considered True unless implements __bool__ or __len__ (in that case __bool__ or __len__ is used to decide). Not practical example: >>> class A(list): ... def __bool__(self): return False ... >>> a = A([1,2,3]) >>> print(len(a), a, bool(a)) 3 [1, 2, 3] False RE: if i had written my own language - Kebap - Apr-02-2017 (Apr-02-2017, 03:13 AM)Skaperen Wrote: if i had written my own language there are some things i would have done differently. Let me guess, a string containing the word "false" would be evaluated to the boolean value False? How about adding strings containing the words "two" and "three"? Will the result be "five" then? RE: if i had written my own language - Skaperen - Apr-03-2017 (Apr-02-2017, 04:28 PM)Kebap Wrote:(Apr-02-2017, 03:13 AM)Skaperen Wrote: if i had written my own language there are some things i would have done differently. i want a funny button in addition to a like button. but yeah, i would have valid code expression of any value of the type/class return that value. so if the language accept "False" but not "false" then the function of that type will, as well. but i don't really see a problem with a special set of functions to do that. this could probably be done with the help of exec(). i might try that. one feature my language would have is a way to add/extend/replace methods of standard type classes like bool, int, float, str, etc. RE: if i had written my own language - micseydel - Apr-03-2017 (Apr-03-2017, 01:55 AM)Skaperen Wrote: this could probably be done with the help of exec()There is a safe alternative for this use case Of course, exec / eval can be made safe with scoping, but it still seems heavy-handed here given ast.literal_eval.
RE: if i had written my own language - wavic - Apr-03-2017 (Apr-02-2017, 02:41 PM)zivoni Wrote:(Apr-02-2017, 01:49 PM)wavic Wrote: Non-empty object is always True. You cheat ![]() RE: if i had written my own language - zivoni - Apr-03-2017 (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)) Indeed this is just a starting point, much more effort would be needed to make it as powerful as INTERCAL...
|