robhagemans / pcbasic

PC-BASIC - A free, cross-platform emulator for the GW-BASIC family of interpreters
http://www.pc-basic.org
Other
393 stars 48 forks source link

DEF FN clobbers variables in argument list #200

Closed goldnchild closed 2 years ago

goldnchild commented 2 years ago

Bug report

Problem

According to the manual,

DEF FN[ ]name [(arg_0 [, arg_1] ...)] = expression

Defines a function called [FN] name (or FN name: spaces between FN and name are optional). On calling FNname( ... ), expression is evaluated with the supplied parameters substituted. Any variable names used in the function that are not in the argument list refer to the corresponding global variables.

Program

100 DEF FN MYNOT(X)=(X=0)*-1 110 FOR X = 1 TO 100 : PRINT X, FN MYNOT(20) : NEXT

this will print 21 0 continuously.

Crash log

Notes

PC-BASIC version: 2.0.2 Operating system version: ubuntu 20.04

robhagemans commented 2 years ago

Hi, you're using an old version, please use the latest release (which doesn't have this issue).

goldnchild commented 2 years ago

Yes, trying with ubuntu 22.04 which has version 2.0.4-3 works fine.

A workaround is just to use a unique identifier that doesn't match the program's variables, like DEF FN myfunc(xarg0) instead of just DEF FN myfunc(x)

Thanks again for your pcbasic program. There's nothing like hacking out a little program in basic.