A request for opinion on proc read xlx integer in van Vliet
Jose E. Marchesi
jemarch@gnu.org
Fri Feb 20 10:34:20 GMT 2026
> Hello again;
>
> This appears in van Vliet's transput:
>
> #<#{PROC read xlx integer = ({REF #L# {INT i) {BOOL:
> # if an integer is read successfully,
> it is assigned to 'i', and the routine returns true;
> otherwise, it returns false #
> {BEGIN^BOOL ok:= {TRUE, {BOOL neg = k = "-";
> (neg {OR k = "+" | skip spaces);
> ({NODIGIT k | mend char(radix10digit, "0"));
> #L# {INT j:= #K# chardig(k);
>
> {WHILE
> {IF status {OF cover {OF f {SAYS line ok
> {THEN get char(f, k);
> {IF^NODIGIT k
> {THEN backchar(f); {FALSE
> {ELSE (ok | ok:= j {ADD chardig(k)); {TRUE
> {FI
> {ELSE^FALSE
> {FI
> {DO^SKIP^OD;
> {IF ok {THEN i:= (neg | -j | j) {FI;
> ok
> {END#>#;
>
> This will expand to
>
> proc read_short_short_integer(ref short short int i) bool: ...
> proc read_short_integer(ref short int i) bool: ...
> proc read_integer(ref int i) bool: ...
> proc read_long_integer(ref long int i) bool: ...
> proc read_long_long_integer(ref long long int i) bool: ...
>
> This "proc" is immediately followed by
>
> {PROC read l real = ({UNION(#<#{REF #L# {REAL#>#) r) {BOOL:
> # similar to 'read xlx integer', for real numbers #
>
> I'm not going to copy/paste the rest of it. Note that it chooses to take a
> union of the various lengths of reals rather than creating
>
> proc read_real(ref real r) bool:...
> proc read_long_real(ref long real r) bool: ...
> proc read_long_long_real(ref long long real r) bool: ...
>
> I find this kind of awkward. He only references read_xlx_integer once, in
> the body of read_l_real. But even so.
>
> I would appreciate any opinions offered!
I don't know why van Vliet decided to use an union in this case, rather
than expansion. I think we should prefer expansion for efficiency
reasons: balancing is done at compile-time.
More information about the Algol68
mailing list