Skip to content

procs.prg: on VFP 9.0.0.7423, Second() resolves to the SECONDS() abbreviation even though the program declares PROCEDURE Second #37

Open

Description

@hemstreet

procs.prg defines PROCEDURE Second returning "second", and the golden expects ? Second() to print second. On my VFP 9 (09.00.0000.7423, started with -A) it prints a seconds-since-midnight value instead. SECOND is not itself a native function — but it is a four-plus-character abbreviation of SECONDS, and the product resolves the abbreviation even though the program declares a procedure with that exact name:

? Second()        && prints 51611.465 on 7423 — SECONDS(), the abbreviation
DO Second         && prints "proc ran" — DO prefers the procedure

PROCEDURE Second
  ? "proc ran"
  RETURN "second"

Measured output on 09.00.0000.7423, -A start:

 51611.465
proc ran

The compiler models the opposite choice on purpose — compiler.rs suppresses the abbreviated lookup when the name is declared in the program:

let found = builtins::lookup(&name.upper)
    .or_else(|| (!self.declared.contains(&name.upper))
        .then(|| builtins::lookup_abbreviated(&name.upper)).flatten());

That is the friendlier design, but it is not what the product does, and the golden pins the VM's behavior rather than Visual FoxPro's. Suggestions:

  1. Re-measure procs.prg; on my build the checked-in text does not reproduce.
  2. Match the product: resolve a unique 4+-character built-in abbreviation for name() calls even when the name is declared (DO name keeps preferring the procedure — worth measuring both forms while at it). One caution before coding it: not every built-in accepts a 4-character abbreviation — measured on 7423, ? GETW("a b c") raises error 1, File 'getw.prg' does not exist., instead of resolving to a GETWORD* function — so the rule wants measuring per name rather than assuming the whole registry abbreviates. (GETW is also a two-way ambiguous prefix, which may be exactly why.)
  3. Rename the test procedure to something that is not a built-in prefix, so procs.prg still covers DO/PROCEDURE/RETURN without the shadowing trap.

A side-effect makes this easy to spot in a sweep: the program prints a clock value on the product, so its output changes every run (see #35).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions