On 15 Dec 2003 at 11:19, Frank Heckenbach wrote:
[...]
I always wanted the extended syntax
nil := ParamCount;
to get the benefits of being able to throw away the return value with the clarity that you are doing so and without the necessity to create junk variables.
Yes for semantics, no for the syntax.
`nil' is a constant, and it's of pointer type. This assignment would violate both rules (and basically create a completely different thing by the same name). I don't think we should follow the example of some other languages to squeeze out the last bits of unused syntax (usually accompanied by worse error recognition).
What I could imagine is a built-in procedure `Ignore', `IgnoreValue', `Discard' or so which takes one parameter of arbitrary type and does nothing.
Or perhaps (but less preferable IMHO) a type-cast to `Void' (as in C) ...
Do any other compilers have something like that?
FWIW, Delphi has something called a Variant, which is type-compatible with all sorts. We could have a more limited kind of Variant. This is what the Delphi 7 help file says about "Variant":
"Sometimes it is necessary to manipulate data whose type varies or cannot be determined at compile time. In these cases, one option is to use variables and parameters of type Variant, which represent values that can change type at runtime. Variants offer greater flexibility but consume more memory than regular variables, and operations on them are slower than on statically bound types. Moreover, illicit operations on variants often result in runtime errors, where similar mistakes with regular variables would have been caught at compile time. You can also create custom variant types.
By default, Variants can hold values of any type except records, sets, static arrays, files, classes, class references, and pointers. In other words, variants can hold anything but structured types and pointers. They can hold interfaces, whose methods and properties can be accessed through them. (See Object interfaces.) They can hold dynamic arrays, and they can hold a special kind of static array called a variant array. (See Variant arrays.) Variants can mix with other variants and with integer, real, string, and Boolean values in expressions and assignments; the compiler automatically performs type conversions.
Variants that contain strings cannot be indexed. That is, if V is a variant that holds a string value, the construction V[1] causes a runtime error.
You can define custom Variants that extend the Variant type to hold arbitrary values. For example, you can define a Variant string type that allows indexing or that holds a particular class reference, record type, or static array. Custom Variant types are defined by creating descendants to the TCustomVariantType class."
Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.bigfoot.com/~african_chief/