[Edu-sig] More re Cross-pollinating Python with other Cool Languages
Kirby Urner
urnerk@qwest.net
Mon, 23 Sep 2002 18:47:26 -0700
Since we're being such busy bees around Rebol here, I thought
I'd bring in another language with some potentially good ideas.
We allow 1e10 in Python (as 1*e^10), which in J opens the door
to other numbers-with-letters-in-em, such as 1r2 (for 1/2),
and 1j2 (for 1+2j), and some even more exotic variants.
When it comes to smoothing a newbie's access to a first language,
which might well be Python, I come up against such things as:
(1j)^10 is an unsupported operand type for ^
yet pow(1j,10) is just fine. Why not have ^ invoke pow internally,
if pow is more able to manage complex arguments?
Anyway, the idea wanted to underline was the coolness of
letting 1r2 mean 1/2 -- it's a primitive number, like 1e10,
not a 'string' result of repr(). If Python ever incorporates
a rational number type at the primitive level, I wonder if
this'd be a way to go. 1r2 could still be an object, just
like 1e10 is e.g.
>>> dir(1e10)
['__abs__', '__add__', '__class__', '__cmp__', '__coerce__',
'__delattr__', '__div__', '__divmod__', '__doc__', '__float__',
'__floordiv__',
'__getattribute__', '__hash__', '__init__', '__int__', '__long__',
'__mod__', '__mul__', '__neg__', '__new__', '__nonzero__',
'__pos__', '__pow__', '__radd__', '__rdiv__', '__rdivmod__',
'__reduce__', '__repr__', '__rfloordiv__', '__rmod__', '__rmul__',
'__rpow__', '__rsub__', '__rtruediv__', '__setattr__', '__str__',
'__sub__', '__truediv__']
I imagine dir(1r2) would get you much the same, but also __numerator__
and __denominator__ or some such (for extracting either integer
part). E.g.
>>> 1r2 .__denom__()
2
>>> 3r4 .__numer__()
3
that kind of thing.
Kirby