On 21/01/17 20:19, Paul Isaacs wrote:
Hello,
How is the production type-inquiry used?
var p : integer;
type q = type of p;
How would it be possible that inquiring as to the type of p is useful? Under what circumstances would the type of p not be already known?
Even if the type of p were not known, how would q be usable if its type were not fixed?
The only reference I can find is in the GNU-Pascal Manual.
function CompilerAssert( condition : boolean, result : Anytype ) : type of Anytype;
What would be returned? Unless Anytype is restricted to types that CompilerAssert is aware of.
Regards,
Paul Isaacs
Gpc mailing list Gpc@gnu.de https://www.g-n-u.de/mailman/listinfo/gpc
Hi Paul,
Perhaps it is some sort of equivalent to overloaded functions? You might find the ISO spec handy, though it is not an easy read! www.pascal-central.com/docs/iso10206.pdf
6.4.9 Type-inquiry
A type-inquiry shall denote a type, bindability, and initial state.
type-inquiry = 'type' 'of' type-inquiry-ob|ect . type-inquiry-ob|ect = variable-name | parameter-identifier .
The type denoted by a type-inquiry shall be the type possessed by the variable-identifier or parameter- identifier contained by the type-inquiry. The bindability denoted by a type-inquiry shall be the bindability possessed by the variable-identifier or parameter-identifier contained by the type-inquiry.
The initial state denoted by a type-inquiry shall be the initial state possessed by the variable-identifier or parameter-identifier contained by the type-inquiry. A parameter-identifier in a type-inquiry-object shall have its defining-point in a value-parameter-specification or variable-parameter-specification in the formal-parameter-list closest-containing the type-inquiry-object.
Example: procedure p(var a : VVector); var b : type of a; {parameter a and variable b will have the same type}
If you can figure out what that means, please let me know!
Regards, Peter