CBFalconer wrote:
Frank Heckenbach wrote:
(AFAIK, `WriteLn' requires compiler magic in any compiler since it allows for an infinite number of combinations of number and types of arguments.)
writeln(f) (or writeln, defaulting to writeln(output)) is the only pure form. Anything else is defined in terms of shorthand.
writeln(f, a) is expected to expand to "write(f, a); writeln(f);" Similarly, if a is not a single simple object, write(f, a, b) is expected to expand to "write(f, a); write(f, b)". There is no magic, and especially no variable parameter lists. This has been clearly spelled out since the User Manual and Report.
The action of write(f, a) for non text files is spelled out in terms of f^ and put.
Similar things apply to read and readln.
I repeat - there is NO MAGIC.
Semantically not, but syntactically it is magic. You can't define such transformations in Pascal code (not even with GPC's current preprocessor ;-).
This is what I usually mean when talking of magic. On the runtime side you can always do with regular routine calls. The question is which kind of transformations the compiler has to do to get there, or simply whether it's possible (at least in principle) to implement those predefined things in pure Pascal code. For some it's easily possible (e.g. `Odd'), some would require a finite amount of overloading (e.g., `EOLn'), some require a certain amount of untypedness (e.g., `EOF' -- accepting all `file of Foo' types, though they're similar enough in probably any implementation to be able to be handled by common code), some must be able to accept an arbitrary number of parameters of the same type (at least from a certain point; e.g., `Write' on typed files), but AFAIK only `Write[Ln]', `Read[Ln]' (and `WriteStr', `ReadStr' in EP) can have both an arbitrary number of arguments and different types for each argument.
Frank