• Algol 68 / Genie - event routine for reading from strings with 'gets'?

    From Janis Papanagnou@21:1/5 to All on Tue Sep 2 06:20:34 2025
    I'm using Algol 68 with the Genie specific extension 'gets', here
    to read real numbers from strings.

    I wanted to polish the data input interface to become more robust.
    My program is reading in real values, either from the command line,
    or from the keyboard, or both. Entering a non-real data string the
    program aborted with an error message (i.e. in my initial version).

    So I defined the event handler 'on value error' to catch that

    on value error (stand in,
    (REF FILE file) BOOL : ( fix_input (0.0); TRUE ) );

    which works as advertised for the interactive keyboard input in the
    else-branch of this code fragment

    REAL k;
    IF argind <= argc THEN # input from command line #
    STRING optarg := argv (argind);
    argind PLUSAB 1;
    gets (optarg, k);
    printf (($ g(6) l $, k))
    ELSE # interactive input #
    read ((k, newline))
    FI;

    Is such an event handler solution possible for the _string input_ with
    'gets' (in the then-branch), as well?

    Currently the 'gets' function throws an error if non-real command line parameters are provided. (Note: for command line argument that's in my
    case acceptable, but generally if would be nice to have a handler for
    that input form as well.)[*]

    Janis

    BTW; I had mentioned in another thread that I find the event handler
    handling peculiar and not smoothly integrating in the control flow.
    Initially I wanted a "redo"-functionality but couldn't get a working
    solution. So I restricted it (as shown above) to just interpret wrong
    input as "0.0" to at least prevent that annoying error message. :-/

    [*] I think, implicitly the 'gets' relies on 'associate', but I'm not
    sure whether that's actually a hindrance, or whether it opens some
    possible solution; and, if at all, without undesired side-effects.

    BTW; one of the changes I'd liked to have seen in Genie with 'gets'
    is that it's not defined to require a REF STRING but instead accept
    STRING items, to avoid the "unnecessary" hack with a LOC temporary.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)