• Algol 68 / Genie - catching "value error" event with 'gets'

    From Janis Papanagnou@janis_papanagnou+ng@hotmail.com to comp.lang.misc on Tue Sep 8 22:54:54 2026
    From Newsgroup: comp.lang.misc

    Algol 68 supports event handlers to catch (and handle) mismatches
    of read-in values WRT the target variable's type. This works fine
    with all the standard I/O ("transput") with the Genie interpreter,
    e.g. in contexts like

    FILE in; REAL k; CHAR c;
    get (in, k);
    get (in, c);

    where the input data doesn't match (e.g.) the syntax of a 'real'.

    Genie now also supports a 'gets' procedure to read in (and parse)
    values of arbitrary types from a string instead of a file, like

    STRING str := "..."; REAL k; CHAR c;
    gets (str, k);
    gets (str, c);

    The event handlers (that may be used in the first case) require a
    FILE parameter to work with. Though there seems to be no comparable
    event handler function to catch and handle such value syntax errors
    in the second case (when reading from a string).

    Any suggestions?

    Janis

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Carlos H@pragus@centrum.cz to comp.lang.misc on Thu Sep 17 16:29:46 2026
    From Newsgroup: comp.lang.misc

    On 08/09/2026 22:54, Janis Papanagnou wrote:
    Algol 68 supports event handlers to catch (and handle) mismatches
    of read-in values WRT the target variable's type. This works fine
    with all the standard I/O ("transput") with the Genie interpreter,
    e.g. in contexts like

    -a FILE in; REAL k; CHAR c;
    -a get (in, k);
    -a get (in, c);

    where the input data doesn't match (e.g.) the syntax of a 'real'.

    Genie now also supports a 'gets' procedure to read in (and parse)
    values of arbitrary types from a string instead of a file, like

    -a STRING str := "..."; REAL k; CHAR c;
    -a gets (str, k);
    -a gets (str, c);

    The event handlers (that may be used in the first case) require a
    FILE parameter to work with. Though there seems to be no comparable
    event handler function to catch and handle such value syntax errors
    in the second case (when reading from a string).

    Any suggestions?
    Associate a file to the string and use file procs/event handlers.

    C.
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Janis Papanagnou@janis_papanagnou+ng@hotmail.com to comp.lang.misc on Thu Sep 17 16:52:59 2026
    From Newsgroup: comp.lang.misc

    On 2026-09-17 16:29, Carlos H wrote:
    On 08/09/2026 22:54, Janis Papanagnou wrote:
    Algol 68 supports event handlers to catch (and handle) mismatches
    of read-in values WRT the target variable's type. This works fine
    with all the standard I/O ("transput") with the Genie interpreter,
    e.g. in contexts like

    -a-a FILE in; REAL k; CHAR c;
    -a-a get (in, k);
    -a-a get (in, c);

    where the input data doesn't match (e.g.) the syntax of a 'real'.

    Genie now also supports a 'gets' procedure to read in (and parse)
    values of arbitrary types from a string instead of a file, like

    -a-a STRING str := "..."; REAL k; CHAR c;
    -a-a gets (str, k);
    -a-a gets (str, c);

    The event handlers (that may be used in the first case) require a
    FILE parameter to work with. Though there seems to be no comparable
    event handler function to catch and handle such value syntax errors
    in the second case (when reading from a string).

    Any suggestions?

    Associate a file to the string and use file procs/event handlers.

    Thanks. That's a good idea! Actually I used 'associate' for the first
    time just yesterday in another project (to obtain some "string-stream" functionality as in C++) and it had occurred to me that it might serve
    for that purpose; though yet I haven't tried whether it works, so also
    thanks for the confirmation - I'll now get back to that other project
    and try it.

    Janis

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Janis Papanagnou@janis_papanagnou+ng@hotmail.com to comp.lang.misc on Thu Sep 17 17:43:35 2026
    From Newsgroup: comp.lang.misc

    On 2026-09-17 16:52, Janis Papanagnou wrote:
    On 2026-09-17 16:29, Carlos H wrote:
    On 08/09/2026 22:54, Janis Papanagnou wrote:
    Algol 68 supports event handlers to catch (and handle) mismatches
    of read-in values WRT the target variable's type. This works fine
    with all the standard I/O ("transput") with the Genie interpreter,
    e.g. in contexts like

    -a-a FILE in; REAL k; CHAR c;
    -a-a get (in, k);
    -a-a get (in, c);

    where the input data doesn't match (e.g.) the syntax of a 'real'.

    Genie now also supports a 'gets' procedure to read in (and parse)
    values of arbitrary types from a string instead of a file, like

    -a-a STRING str := "..."; REAL k; CHAR c;
    -a-a gets (str, k);
    -a-a gets (str, c);

    The event handlers (that may be used in the first case) require a
    FILE parameter to work with. Though there seems to be no comparable
    event handler function to catch and handle such value syntax errors
    in the second case (when reading from a string).

    Any suggestions?

    Associate a file to the string and use file procs/event handlers.

    Thanks. That's a good idea! Actually I used 'associate' for the first
    time just yesterday in another project (to obtain some "string-stream" functionality as in C++) and it had occurred to me that it might serve
    for that purpose; though yet I haven't tried whether it works, so also
    thanks for the confirmation - I'll now get back to that other project
    and try it.

    Just implemented it and it works as advertised. - Thanks again!


    The only imperfection is that it's a rather bulky code; where I
    originally (for the case that the types must be provided correctly)
    just needed

    gets (LOC STRING := value, var OF opt_i);

    I now have

    get generic value (var OF opt_i);

    with the additional [nested] function

    PROC get generic value = (REF GENERIC par) VOID :
    BEGIN
    FILE stream;
    STRING value_copy := value;
    associate (stream, value_copy);
    on value error (stream, (REF FILE f) BOOL : (
    error ("Illegal value for option '" + name + "'!"); TRUE ) );
    get (stream, par);
    END;


    But it works, and that is the important thing. :-)

    Janis

    --- Synchronet 3.22a-Linux NewsLink 1.2