Testing for numerics

Dar Scott dsc at swcp.com
Thu Oct 5 15:04:51 EDT 2006


On Oct 5, 2006, at 11:35 AM, Mark Wieder wrote:

> Wednesday, October 4, 2006, 5:47:16 PM, you wrote:
>
>> I think this underscores the need for REAL type checking. I was told
>> that a positive integer would return true if "is a date" is used.
>
> BZ #2783

People have created interesting bugs related to types in languages  
with strong typing.

Many languages have type integer which is not an integer but some  
uniform representation of some subset of integer.

Suppose some number in a program should only be a prime.  Should a  
prime type be invented?

Some languages infer types.

Types are a hint to compilers and in some languages are a ball and  
chain to the compiler.  Types allow a developer to organize thoughts  
and to catch errors.  However, types are part of a more general  
mechanism related to constraints on the ranges and domains functions  
and commands.  This mechanism might involve good comments, runtime  
assertions, assertions for analysis, assertions for compiling, and  
typing.  This can be generalized to I/O and sometimes intermediate  
values.

In this particular case, the common Revolution approaches are 1. to  
comment constraints or 2. to check for value errors and do something  
about those.

In functions I use internally, I usually use comments to describe the  
sets of allowed values for parameters.  In functions made available  
to customers, I use one or both.  Sometimes, I am pretty casual about  
what a parameter might be.

Revolution lends itself to runtime assertions and I expect that many  
folks have rolled their own.

The detailed syntax of Revolution is poorly defined, but I would not  
be surprised if someone someday creates a smart lint that can handle  
simple proofs.  That may be a while.  I would not be surprised if the  
compiler might catch more in the future based on ranges of values.

As far as 'is a date', I tried '"dinner and movie" is a date' in the  
message box and got false, so 'is a date' might be built with an  
assumption of a specific meaning for 'date'.

I have enjoyed strong types in programming, but I don't think typing  
is what is needed here.

Dar



More information about the use-livecode mailing list