Frank Heckenbach wrote:
Gale Paeper wrote:
Oh dear, I'm quite shocked. Why do people make up such strange things? They could easily have made two separate routines (say `ScanEQ' and `ScanNE' -- this might be what can be implemented reasonably in GPC, with different syntax (*)) -- it would have taken them just one more predefined identifier instead of a completely irregular new syntax rule ...
I'm not sure where in the chain from Apple's UCSD Pascal to MPW Pascal the change was made, but in MPW Pascal `ScanEQ' and `ScanNE' is provided instead of Scan.
Even the same names that I'd just made up? :-)
Yep. Although they're documented with a lower case spelling but that's irrelevant for Pascal.
[snip]
How about:
{$define Scan(A, B, C) repeat
Scan in UCSD Pascal is a function, so a compatibility macro must be usable as a function.
That B parameter is so demented that it causes mind rot. Completely forgot about the function aspects.
var ScanExpression : string(4) value (#B); if (Length(ScanExpression) = 4) and_then (index(ScanExpression,
'<>') = 1) then ScanNE((A),ScanExpression[4],(C))
BTW, would these parentheses actually be necessary in Pascal? Sure, it won't hurt to add them, but without the infamous comma operator of C, I think there could be no confusion here, anyway.
Probably not. Just a C macro rule of thumb bleeding over to Pascal usage.
else if (Length(ScanExpression) = 3) and_then (index(ScanExpression,
'=') = 1) then ScanEQ((A),ScanExpression[3],(C)) else ParameterError; until true;
`repeat ... until True'? (Without trailing `;', BTW.) Perhaps you've read/written too many C macros of the kind `do ... while (0)'.
In Pascal, however, `begin ... end' would seem simpler (in a statement context), wouldn't it? (One of my favourite arguments why semicolon as a separator is better, BTW. :-)
Been reading too many C macros.
[snip]
Also, your suggestion would shift quite some work to runtime (string comparisons), and a parameter error wouldn't be detected until runtime. (I didn't check for it in my version, but it could be added and checked for at compile-time.)
I was thinking that the only way a macro hack would work is if the B parameter was in a form where everything was compile-time constant expressions and all but one of ScanEQ , ScanNE, or ParameterError would get optimized away by the compiler.
In regards to ParameterError, that was more for completeness than anything else. At least to me, the only reason for this sort of macro hack is to aid in porting old, presumably correct code so there shouldn't be any errors to detect anyway (or at least one hopes so).
Adriaan van Os wrote:
The CH part can be an expression and it is quoted for char constants. I think it is (much) better to replace Scan by ScanEQ and ScanNE in the source code.
I agree. UCSD Scan is one of those things that is best left in the graveyard of bad ideas.
Gale Paeper gpaeper@empirenet.com