assigning to arg inside function definition?

51 Views Asked by At

Trying to read some old BASIC code to do a port, and coming across this mind-bending concept:

1150 DEF FNB(Q)=Q+8*((Q=9)-(Q=0))

What... is going on here? How can you assign to the parameter like that? Why isn't this equivalent to Q+8*(9-0)?

I wrote a little demo to investigate, but it didn't yield anything that I expected:

10 DEF FNB(Q)=Q+8*((Q=9)-(Q=0))
20 PRINT FNB(1)
30 PRINT FNB(2)
20 PRINT FNB(3)
30 PRINT FNB(10)
RUN
 1
 2
 3
 10
Ok

I must be doing something wrong, because FNB can't be an identity function.

Can someone explain what BASIC is actually doing in this function? And why my demo isn't being helpful?

1

There are 1 best solutions below

3
Grant Birchmeier On BEST ANSWER

Argh, I just got it.

That's not assignment inside the function, it's an equality test!

If they are equal, it returns -1 (why...), else 0.

For example:

10 print 9=9
20 print 9=8
RUN
-1
 0
Ok

Man, it's been a long time since I used a language that used = for equality...