Author Topic: Incomplete one-liner execution  (Read 1257 times)

0 Members and 1 Guest are viewing this topic.

Brian Alvarez

  • Guest
Incomplete one-liner execution
« on: May 09, 2019, 10:33:19 PM »
This code:

Code: [Select]
floor(l1 + ((¤rand() / 32767) * (l2 - l1)))
Fails... while this:

Code: [Select]
    double rv = (¤rand() / 32767)
    print floor(l1 + (rv * (l2 - l1)))

Gives a good result.

Also this:

Code: [Select]
print (¤rand() / 32767) + " THE RESULT"
Omits the "THE RESULT" string. Seems like the one liner aborts after the function calls.

 Would you help me get the latest version of oxygen up and running? I dont know what i might be doing wrong....


Brian Alvarez

  • Guest
Re: Incomplete one-liner execution
« Reply #1 on: May 10, 2019, 06:47:23 PM »
I just upgraded to the newest version of Oxygen. The issue i was having before upgrading, still occurs in the newest version:

Code: [Select]
declare function rand  lib "msvcrt.dll" alias "rand" () as int
declare function srand lib "msvcrt.dll" alias "srand" (int seed)

FUNCTION rnd(byval int l1, l2) AS DOUBLE
    if l1 > l2 then
        int l3 = l1
        l1 = l2
        l2 = l3
    end if
    double rv = (rand() / 32767)
    return floor(l1 + (rv * (l2 - l1)))
END FUNCTION

srand(21123) ' seed the randomizer.

int v
int i

for i = 1 to 10
    v = 2000 + rnd(1, 20) 'this fails. always returns a number smaller than 21     
    'v = rnd(1, 20) + 2000 'this works. this returns a number from 2001 to 2020.     
    print " r: " v chr(13, 10)
next i

Brian Alvarez

  • Guest
Re: Incomplete one-liner execution
« Reply #2 on: May 10, 2019, 07:39:51 PM »

 If i change the data type of the rnd() function from DOUBLE to LONG it works.
SINGLE also fails....

I believe this is a fundamental bug that will affect many other situations...

Brian Alvarez

  • Guest
Re: Incomplete one-liner execution
« Reply #3 on: May 10, 2019, 10:33:27 PM »
Simpler test:

Code: [Select]
FUNCTION rnd(byval int l1, l2) AS QUAD   
    return 1000
END FUNCTION

int v = 0

v = 2000 + rnd(1, 20)   'this fails. produces: 2446896
'v = rnd(1, 20) + 2000   'this works. produces 3000   

print v

Charles Pegge

  • Guest
Re: Incomplete one-liner execution
« Reply #4 on: May 10, 2019, 10:50:09 PM »
Yes, I see the problem.

It concerns mixed float functions and integers. If you make the dest variable v a float. It will work as expected. I will investigate further.

The print problem is a separate issue:

Code: [Select]
'print (¤rand() / 32767) + " THE RESULT"
print( (¤rand() / 32767) + " THE RESULT" )

Brian Alvarez

  • Guest
Re: Incomplete one-liner execution
« Reply #5 on: May 11, 2019, 01:21:25 PM »
 Thanks charles!  :)

 Regarding the print issue, i can also see the logic. It is taking the bracketed part as the parameters of the print function.

Maybe a syntax error should be raised for the + after the brackets?

Added: Nah, nvm. Less error checking is faster. I will make sure to trap syntax errors here.
« Last Edit: May 11, 2019, 01:29:25 PM by Brian Alvarez »

Charles Pegge

  • Guest
Re: Incomplete one-liner execution
« Reply #6 on: May 12, 2019, 02:02:23 AM »
One solution is to insert a null string literal after print:

I'll make o2 do this automatically, whenever the first print term is other than a quote mark.

Brian Alvarez

  • Guest
Re: Incomplete one-liner execution
« Reply #7 on: May 12, 2019, 08:54:42 PM »
Clever...