Front page | perl.perl6.language |
Postings from October 2001
From: RaFaL Pocztarski
October 11, 2001 04:28
Message ID: 3BC58218.9388D20@rfl.pl
David Nicol wrote:
> RaFaL Pocztarski wrote:
> > > First this thread tells me that "123foo" will be 123 in numeric
> > > context. Now I find myself wondering what "123indigo" evaluates
> > > to!
> Also 123. I think that complex numbers, if happening automatically,
> would only match
> ($realpart, $imaginarypart) = /^\b(\d*\.?\d+)\+(\d*\.?\d+)i\b/
> and "123indigo" does not match that.
I'm not sure how strings like "123indigo" should be handled, but I think
that imaginary numbers should also be recognized as complex written 10i
and not only 0+10i. I don't think that imaginary numbers should have
their own class, like real ones have. I would love literals like
10k+4iMi to be valid numbers, but I don't know what others think about
it. But it probably should be just an addition of two numbers, real and
imaginary, not just a complex literal as a whole.
BTW, it reminds me my another bad idea I got some time ago:
Currently in Perl 5 string '2**16' in numeral context evaluates to 2
(with warning). To DWIM it should be 65536.
I know that it would be harder to implement and I won't argue if you
tell me that it's to hard to be worth all the work, but I'd like to know
what do you think about it, maybe it would evolve to a better idea, but
anyway, here's what I thought: strings in numerical context could be
evaluated using all numerical operators like +, -, *, /, **, etc. to
calculate the result. To enter 4294967295 i could use '2**32-1' (I mean
strings of course, like user input etc.) with no need to use eval on the
string, as eval on user input could be unsafe.
Now I have idea that maybe some 'neval' (numerical eval) function should
be useful, and it could be used only when string in numerical context
would normally produce a warning (so normal +'123' won't me any slower).
Such neval could be useful anyway, for using as safe eval for other
things. It could be just eval after removing everything which is not a
numerical operator or number literal, whatever it will mean. :) I'm just
thinking loudly. What do you think about it?
- RaFaL Pocztarski, firstname.lastname@example.org