Login
Back to forumReply to this topicGo to last reply

Posted By

SVS
on 2018-08-22
12:07:59
 DEF FN() question

Maybe it was the hot weather of this summer happy or maybe I'm too much a Plus4 fan happy happy

but I'm wondering why the DEF FNx(y) command does store the address of the variable y.
As known in fact, after the DEFinition, when the program calls the FuNction, the value of the parameter passed to can be everything (another variable, a constant, etc.). Then what's the usefulness to save it in the DEF phase?

Posted By

Charlemagne
on 2018-08-22
15:40:11
 Re: DEF FN() question

Hi SVS,

If I remember well, ...when I developed TV4B... ...I handled "DEF FN " like a variable that points to the location of the value in the original source...

eg.:
10 DEFFNmy(x)=RND(x)+1
20 a%=FNmy(90)
30 PRINT a%

Where:
- "my" is a variable (YES, without "(x)" parameter) that points to "RND(x)+1"
- "FNmy(90)" is interpreted as "RND(90)+1"
...such as "FNmy(90)" replaced with "RND(x)+1" then "x" replaced with "90" and reinterpreted the new form.

Posted By

SVS
on 2018-08-23
13:57:59
 Re: DEF FN() question

Yes Charlemagne you are right, but deeply investigating the name "my" in memory, it stores the address of the start of the formula "RND(x)+1" and the address of the variable "x" (data) too. This last is useless IMO, or am I wrong?

Posted By

Charlemagne
on 2018-08-23
19:09:28
 Re: DEF FN() question

OK, I tried it in YAPE, too and...



...I can see what you are talking about.

So, you are right! It seems to be useless. And you are an explorer! happy

BUT, what can be the explanation? I think that the BASIC compiler automatically creates each new variables, in turn what is the meaning of storing the "X" address ($102C), too? It is very interesting.
...and what is $BB? The code of RND... So the BASIC compiler stores not only the address of the formula and the parameter, but even the function?

Posted By

SVS
on 2018-08-24
10:48:49
 Re: DEF FN() question

The "BB" stored is the first character after the "=" in the DEF FN statement. It can be a number, an alphabetical letter or even a token.
This was unknown even in the site' Plus/4 Encyclopedia, so that I've inserted the information.

Regarding the use of "x" data, maybe the BASIC engineer was considering to use a specific variable, but then it made the very flexible system we are. Remember that "our" BASIC is a reduced version of MS-BASIC... happy

Anybody has other ideas about?



Back to topReply to this topic


Copyright © Plus/4 World Team, 2001-2024. Support Plus/4 World on Patreon