behaviour on encountering invalid float/string type conversion

Issue #35 resolved
Annie Hughes created an issue

Hello again Lajos,

I noticed that in IDL, casting a string as a float returns a floatingpoint 0 when no sensible conversion is possible, whereas in FL, it returns a floatingpoint 0 but it also throws an error that halts execution.

For example, I have a routine dumb_conversion.pro :

pro dumb_conversion
string='fawlty'
var=float(string)
print,'Here is my attempt to convert '+string+': ',var
stop
end

With IDL, I have the following behaviour

IDL> dumb_conversion
\% Compiled module: DUMB_CONVERSION.
\% Type conversion error: Unable to convert given STRING to Float.
\% Detected at: DUMB_CONVERSION 3 /Users/anniehughes/dumb_conversion.pro
Here is my attempt to convert fawlty: 0.00000
\% Stop encountered: DUMB_CONVERSION 5 /Users/anniehughes/dumb_conversion.pro
IDL> print,var
0.00000

Whereas with FL, I have the following behaviour

FL> dumb_conversion
\% Compiled routine: DUMB_CONVERSION
\% Error: FLOAT: invalid conversion: STRING => num, fawlty
\% Execution halted at: DUMB_CONVERSION 3 /Users/anniehughes/dumb_conversion.pro
\% $MAIN$
FL> print,var
0.00000

I agree that casting non-numerical strings as floats is stupid, but was wondering if there is some easy work-around to make fawlty behave as IDL does?

(I ask because the IDL code suite I am testing under FL uses '#' to indicate comment lines in input text files, and until now we lazily just convert these lines to floats and then throw them away… but it seems for FL we would need a different tactic)

thanks again,

Annie

Comments (2)

  1. Lajos Foldy repo owner

    I can reproduce this with FL 0.79.50 on Linux, but 0.79.51 works:

    Fawlty Language 0.79.51 (linux amd64 m64) Copyright (c) 2000-2022, Lajos Foldy

    FL> dumb_conversion
    % Compiled routine: DUMB_CONVERSION
    Here is my attempt to convert fawlty:       0.00000
    % STOP in DUMB_CONVERSION          5  /fl64/home/foldy/dumb_conversion.pro
    %         $MAIN$
    FL>

    (The warning is missing, I have to put it back.)

  2. Log in to comment