Home » Modeling » Epsilon » Operation, asInteger() and EOLInteger constructor
Operation, asInteger() and EOLInteger constructor [message #369106] |
Tue, 28 July 2009 15:57 |
No real name Messages: 92 Registered: July 2009 |
Member |
|
|
Hi there,
Just a quick note really.
The other day I was applying asInteger() to certain Strings (which would
usually be number characters). In the Epsilon book, I saw that an error
would be raised if the Strings weren't of an acceptable form (pg. 33). But
I found this not to be the case.
Looking in the EOLInteger constructor (which I believe asInteger() uses),
I see that if the String isn't of a valid form, the EOLInteger object is
set to 0. And in practice, this was the behaviour I was experiencing,
i.e., I didn't get an error even when the String wasn't a number, e.g.,
'Tilly the cat'.
Given this behaviour, I use the following rather pointless looking
operation to determine if a String can be parsed as an integer:
operation String isInteger() : Boolean {
if(self = '0') {
return true;
}
else if(not(self.asInteger()=0)) {
return true;
}
else {
return false;
}
}
Would it make sense to add an operation to EOLString, which could check if
it could indeed be parsed as an integer? I guess I only suggest this
because if an error was raised after trying to parse an unacceptable
String as an integer, I wouldn't know how to handle the error in Epsilon,
e.g., if the error was an exception thrown by the underpinning Java.
Moreover, it would allow you to check for such cases at runtime without
your application stopping.
Anyway,
Best,
Edd
|
|
|
Re: Operation, asInteger() and EOLInteger constructor [message #369250 is a reply to message #369106] |
Tue, 28 July 2009 21:41 |
Dimitrios Kolovos Messages: 1776 Registered: July 2009 |
Senior Member |
|
|
Hi Edd,
Sounds like a reasonable enhancement indeed :) Could you please file an
enhancement request in the bugzilla and post the link here?
Cheers,
Dimitris
Edward Turner wrote:
> Hi there,
>
> Just a quick note really.
>
> The other day I was applying asInteger() to certain Strings (which would
> usually be number characters). In the Epsilon book, I saw that an error
> would be raised if the Strings weren't of an acceptable form (pg. 33).
> But I found this not to be the case.
>
> Looking in the EOLInteger constructor (which I believe asInteger()
> uses), I see that if the String isn't of a valid form, the EOLInteger
> object is set to 0. And in practice, this was the behaviour I was
> experiencing, i.e., I didn't get an error even when the String wasn't a
> number, e.g., 'Tilly the cat'.
>
> Given this behaviour, I use the following rather pointless looking
> operation to determine if a String can be parsed as an integer:
>
> operation String isInteger() : Boolean {
> if(self = '0') {
> return true;
> }
> else if(not(self.asInteger()=0)) {
> return true;
> }
> else {
> return false;
> }
> }
>
> Would it make sense to add an operation to EOLString, which could check
> if it could indeed be parsed as an integer? I guess I only suggest this
> because if an error was raised after trying to parse an unacceptable
> String as an integer, I wouldn't know how to handle the error in
> Epsilon, e.g., if the error was an exception thrown by the underpinning
> Java. Moreover, it would allow you to check for such cases at runtime
> without your application stopping.
>
> Anyway,
>
> Best,
>
> Edd
>
|
|
| |
Re: Operation, asInteger() and EOLInteger constructor [message #571535 is a reply to message #369106] |
Tue, 28 July 2009 21:41 |
Dimitrios Kolovos Messages: 1776 Registered: July 2009 |
Senior Member |
|
|
Hi Edd,
Sounds like a reasonable enhancement indeed :) Could you please file an
enhancement request in the bugzilla and post the link here?
Cheers,
Dimitris
Edward Turner wrote:
> Hi there,
>
> Just a quick note really.
>
> The other day I was applying asInteger() to certain Strings (which would
> usually be number characters). In the Epsilon book, I saw that an error
> would be raised if the Strings weren't of an acceptable form (pg. 33).
> But I found this not to be the case.
>
> Looking in the EOLInteger constructor (which I believe asInteger()
> uses), I see that if the String isn't of a valid form, the EOLInteger
> object is set to 0. And in practice, this was the behaviour I was
> experiencing, i.e., I didn't get an error even when the String wasn't a
> number, e.g., 'Tilly the cat'.
>
> Given this behaviour, I use the following rather pointless looking
> operation to determine if a String can be parsed as an integer:
>
> operation String isInteger() : Boolean {
> if(self = '0') {
> return true;
> }
> else if(not(self.asInteger()=0)) {
> return true;
> }
> else {
> return false;
> }
> }
>
> Would it make sense to add an operation to EOLString, which could check
> if it could indeed be parsed as an integer? I guess I only suggest this
> because if an error was raised after trying to parse an unacceptable
> String as an integer, I wouldn't know how to handle the error in
> Epsilon, e.g., if the error was an exception thrown by the underpinning
> Java. Moreover, it would allow you to check for such cases at runtime
> without your application stopping.
>
> Anyway,
>
> Best,
>
> Edd
>
|
|
| |
Goto Forum:
Current Time: Fri Sep 20 00:07:00 GMT 2024
Powered by FUDForum. Page generated in 0.04440 seconds
|