Menu

Integer functions fail

2016-12-14
2016-12-30
  • Marcos Cruz

    Marcos Cruz - 2016-12-14

    I have found out this problem:

    new
    10 def fna%(x)=100
    20 print fna%(0)
    run
    Out of memory in 20
    

    This happens when the "%" suffix is used ("!" and "#" work fine). I have tried the same code in the original interpreter on DOSBox, and it works.

     
  • Rob Hagemans

    Rob Hagemans - 2016-12-19

    Hi, thanks for reporting, I'll investigate. Which version of PC-BASIC were you using?

    Thanks
    Rob

     
  • Rob Hagemans

    Rob Hagemans - 2016-12-19

    Hi Marcos, sorry, I can't reproduce with version 15.08.11 or with 16.12.0rc0. The above code gives me
    100

    as I would expect.

    If you're using an older version, could you please update and try if the issue still exists?

    Thanks
    Rob

     
  • Marcos Cruz

    Marcos Cruz - 2016-12-27

    Sorry for the delay. I use version 15.08.11, the first one I ever installed. I've just tried the code, and now it works. It's really strange, because It failed the other day, and I tried it several times in new sessions of the emulator, in order to be sure. I'll try to discover what happened. Thanks.

    Update: I forgot I used version 15.08.10 first and upgraded it on 2016-12-09, but the problem arised days later, with version 15.08.11.

     

    Last edit: Marcos Cruz 2016-12-27
  • Rob Hagemans

    Rob Hagemans - 2016-12-28

    Hi Marcos, thanks for letting me know. Unfortunately it can be hard to reproduce bugs with an interpreter, because it stores so much internal state - it may be that the bug gets triggered if certain variables exist, etc.

    In case it helps, the Out of Memory error is thrown by FN calls if the function is recursive: there is no way to terminate recursion in a one-line function, since GW-BASIC does not have a ternary operator; hence the call stack just keeps growing until it uses up all memory. PC-BASIC signals this condition early and throws the error right away when a function cals itself recursively. Perhaps it throws it in error if A% already exists as a variable, or something similar. I'll have to play around a bit to see if there is a problem there.

    Cheers
    Rob

     
    • Marcos Cruz

      Marcos Cruz - 2016-12-30

      In case it helps, the Out of Memory error is thrown by FN calls if the function is recursive: there is no way to terminate recursion in a one-line function, since GW-BASIC does not have a ternary operator; hence the call stack just keeps growing until it uses up all memory. PC-BASIC signals this condition early and throws the error right away when a function cals itself recursively. Perhaps it throws it in error if A% already exists as a variable, or something similar.

      Thanks. That was exactly what I was going to ask you! I can confirm the error happens during the excecution of a program of mine I'm porting from other dialect of BASIC. I'm trying to isolate the error conditions.

       
  • Anonymous

    Anonymous - 2017-01-25

    I just installed 15.08.11 for the first time today. I had a similar problem with a single precision function that I wrote. I hadn't saved the file yet. After reading this forum, I simply saved, closed PC-BASIC, re-launched, reloaded my program, and it magically worked. It's a very short test program that simply defines a function and calls it. There's definitely no recursion there, and the same code worked after restarting PC-Basic.