OK, programming has some pretty abstract concepts. Sometimes you just have to power through them. They make sense once you get the hang of them.
Variables are the names of objects. In many computer languages some variables name the memory containing the values and some variables name the memory containing a pointer to the memory contianing the values. So far my tests indicate LUA variables name the memory containing the values and that no two variables will ever name the same memory. The Computer Science people call this "pass by value". When a language uses variables to name the memory containing a pointer to the memory containing the values and can make two variables point to the same memory locations the Computer Science people call this "pass by reference". It doesn't matter if LUA actually names pointers to memory containing the values or names the memory containing the values. What does matter is that one can't change the value by using one name and have it change the value of another variable.
While variables are the names of objects multiple objects can have the same name as long as the computer can decide which is being named at any given time. The contexts under whic any particular variable can be identifed by nane is its "scope". Identifying the scope of a variable can be daunting. Further, using a variable name improperly can introduce bugs. To limit the scope of a varaible one identifies it as local. This program:
function y()
x=2
z()
print ('in y, x=',x)
end
function z()
x=3
end
y()
prints "in y, x=3".
This program:
function y()
local x=2
z()
print ('in y, x=',x)
end
function z()
x=3
end
y()
prints "in y, x=2".
The same will happen if I define x as local to function z.
Next time I'll go into types of variables.
A journal of a FoldIt player's thoughts while learning to play the game and it's application to improving our lives.
Since this is a journal you may find starting from earlier articles helpful. I have covered a bit about the science, the FoldIT user interface, GUI recipes, and Script recipes. If you give me hints where I could be helpful I will focus in that general direction to my discretion. Currently I am going though the basic concepts of LUA script recipes. Once I get past intoductory LUA scripting I can start exploring the science of folding proteins by using LUA scripts.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment