On Mon, 8 Mar 2004, Ian Morgan wrote:
> Firstly, is there a function for checking if an input is an integer?
-isintegral- tests an item to see if it is an integer. (-isinteger- does
a more specific machine-dependent test connected with the representation
used. You probably want -isintegral-.)
> Alternatively I have a list ![== am ?age:isage ==] where isage checks to see
> if the value is a number and, if it is, save it into a lexicon.
>
> I have done it so isage just checks to see if the item is between 1 and 9...
> and then i realised that it won't work if the number is more than one digit.
> I seem to remember reading somewhere that a * (asterisk) allows more than
> one match but i can't find it again - could someone point out the relevant
> help file !
You haven't said how you generate your list, but if you are using e.g.
-readline- the itemiser automatically converts strings that can
represent numbers into ordinary internal representations of numbers. If
this is so then all you need is
define isage(age) /* -> boolean */;
age.isintegral and age >= 0 and age <= MAXAGE
enddefine;
where MAXAGE is a constant giving the largest age you are willing to
accept as valid.
However, the fact that you have a problem suggests that the age really
is a string or word in your list. The string or word presumably contains
the character codes that would print the number. In this case you can
modify the procedure above to
define isage(age) /* -> boolean */;
if age.isstring or age.isword then strnumber(age) -> age endif;
age.isintegral and age >= 0 and age <= MAXAGE
enddefine;
which will work either way.
David
|