Variable Created At Runtime

Discussions about the BBC BASIC language, with particular reference to BB4W and BBCSDL
MattC
Posts: 114
Joined: Mon 16 Apr 2018, 06:17

Variable Created At Runtime

Post by MattC »

Hi,

I (re)found this under "Procedures and functions" in the help and don't follow the way it works. Could someone please explain the processes behind it so I can understand it more fully.

Code: Select all

INPUT "Enter a variable name: " name$
INPUT "Enter a numeric value for the variable: " value$
dummy% = EVAL("FNassign("+name$+","+value$+")")
PRINT "The variable "name$" has the value ";EVAL(name$)
END
DEF FNassign(RETURN n, v) : n = v : = 0
Thanks

Matt
DDRM

Re: Variable Created At Runtime

Post by DDRM »

Hi Matt,

I'm open to correction here, but my understanding is:

In Fnassign, the variable to which the value is to be assigned is passed by reference (because of the RETURN): that is to say, the variable passed in will be directly affected by what happens in the function.

When you call FNassign (using EVAL to construct the call from the desired name string), it creates a variable with the specified name (since it doesn't already exist), and passes it to the function, which fills in the value.

Hope that's helpful (and something like true - I dare say Richard will let me know if not...)

Best wishes,

D
MattC
Posts: 114
Joined: Mon 16 Apr 2018, 06:17

Re: Variable Created At Runtime

Post by MattC »

Still not sure, but thanks anyway.

I think the problem is I don't fully understand the way EVAL works. But that's OK at the moment. The question was just out of curiosity, rather than practicality.

Thanks again.

Matt