[Gambas-user] Financial program

Doriano Blengino doriano.blengino at ...1909...
Tue Dec 15 17:26:53 CET 2009


Jean-Yves F. Barbier ha scritto:
> Doriano Blengino a écrit :
>   
>>>> A strongness inherited from pascal... I gave a look to many, countless 
>>>>     
>>>>         
>>> hmm, I don't think Pascal can define vars as temperature[-10, +50]
>>>   
>>>       
>> What do you mean precisely? Can you define the properties of such variable?
>>     
>
> means: var name of type = temperature, type = integer, can't go further
> its boundaries [-10, +50] ([-10.0, +50.0] would have a 1/10th degree 
> precision and so on)
>   
Pascal can do it on scalars: "type Tdegrees = -10..50;". The storage 
will be the minimum required (in this case, a shortint, or signed byte). 
If you turn range checking on, then assigning a value out of range 
raises a runtime error. If in your program you have such a wrong 
assignment from a constant expression, then the error will be detected 
at compile time (ie, the compiler is smart enough to detect this). This 
is the "old", standard pascal, where you can't do the same with real 
(floating) numbers because they are not scalar, so by definition they do 
not have ranges, so you can not define subranges (and this is a limit, 
dictated by "pureness" of original pascal). I think that ADA's very 
advanced declarations started from here, adding more capabilities 
(pascal has the same age as C).

In more recent pascal you can overload everything (operators included), 
so you can get a step ahead; but "temperature := temperature+1" always 
means "increment of one unit". This is what is possible without OO. 
Using OO, you must instantiate every variable (because now they are 
objects), write methods and overload assignments and operators, and make 
exactly what you want even with precision 1/10th: writing "temperature 
:= temperature+1" can lead to 1 degree of increment, or 1 tenth of 
degree: it depends on how you implement it.

Regards,
Doriano



More information about the User mailing list