|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|

VariableIn computer science and mathematics, a variable is a symbol denoting a quantity or symbol. In mathematics, a variable often represents an ''unknown'' quantity; in computer science, it represents a place where a quantity can be stored. Variables are often contrasted with constants, which are known and unchanging. In other scientific fields such as biology, chemistry, and physics, the word variable is used to refer to a measurable factor, characteristic, or attribute of an individual or a system. In a scientific experiment, so called "independent variables" are factors that can be altered by the scientist. For example, temperature is a common environmental factor that can be controlled in laboratory experiments. "Dependent variables" or "response variables" are those that are measured and collected as data. ==General overview== Variables are used in open sentences. For instance, in the formula: x + 1 = 5, x is a variable which represents an "unknown" number. In mathematics, variables are usually represented by letters of the Roman alphabet, but are also represented by letters of other alphabets; as well as various other symbols. In computer programming, variables are usually represented by either single letters or alphanumeric string (computer science)s. ==Why are variables useful?== Variables are useful in mathematics and computer programming because they allow instructions to be specified in a general way. If one were forced to use actual values, then the instructions would only apply in a more narrow, and specific, set of situations. For example: specify a mathematical definition for finding the square (algebra) of ANY number: square(x) = x · x. Now, all we need to do to find the square of a number is replace ''x'' with any number we want. *square(''x'') = ''x'' · ''x'' = ''y'' *square(1) = 1 · 1 = 1 *square(2) = 2 · 2 = 4 *square(3) = 3 · 3 = 9 etc... In the above example, the variable x is a "placeholder" for ANY number. One important thing we are assuming is that the value of each occurrence of x is the same -- that x does not get a new value between the first x and the second x. In computer programming languages without referential transparency, such changes can occur. ==Computer programming== In programming languages, a ''variable'' can be thought of as a place to store a ''value (computer science)'' in computer memory. In general, a variable binds an object (computer science) to a name so that the object could be accessed later, much like a person has a name and people could refer to him by that name. This is analogous to the use of variables in the mathematics and variables in computer programming work usually in the similar manner. Put in another way, an object could exist without it being bound to a certain variable. Typically, the name of a variable is bound to a particular address of some bytes on the memory, and any operations on the variable would manipulate that block. This is called ''name binding''. If the space is way too large or its size is unknown beforehand, the use of reference (computer science) is more common, in which a value is not directly stored in the variable but a location information for it is. Importation questions about variables are twofold: its life-time and scope. For space efficiency, a memory space needed for a variable is allocated when first used and freed if no longer needed. The scope helps determine the life-time of variables. Usually, a variable is set to reside in some scope (programming) in program code, and entrance and leave of the scope coincides with the beginning and ending of a variable life, respectively. Put in conceptual terms, a variable is ''visible'' in its scope, and computers could assume the variable is needed only when it is visible. In this way, however, unused variables might be given a space, which is going to be never used. Because of this, a compiler often warns programmers when a variable is declared but not used at all. While a variable stores simple data like integers and literal strings, some languages allow a variable to store datatype as well. They enable type polymorphism functions to be written. They operate like variables, in that they can represent any type. For example, with the function length -- to determine the length of a list, it is only necessary to know the amount of elements in the list -- the type of the elements does not count, so the type signature can be represented with a type variable and thus is parametric polymorphic.
Variables could be either mutable or immutable. Mutable variables could be thought of ones having l-value while immutable ones having r-value. One characteristic of functional programming is that a variable is immutable. Because immutable variables are semantically the same as constants given a name or constant functions, when one talks about variables, they usually mean mutable variables.
See name (computer science) for naming rules and convention of variable names.
In C++ (not in C), "mutable" is a keyword to allow a mutable member to be modified by a const member function.
----
In programming languages, a variable can be thought of as a place to store a ''value'' in computer memory. More precisely, a variable associates a ''name'' (sometimes called an ''identifier'') with the location of the value; the value in turn is stored as a ''data object'' in this location. The specifics of variable allocation and the representation of values vary widely, both among languages and among implementations of any given language.
===Constant===
A constant is similar, but does not change its value during program execution, and is the same when running the program again. The value is specified only once but the constant can be referenced multiple times in the program. Changing the value is done by a simple change of the program. Using a constant should be distinguished from specifying the value multiple times in the program. The latter would make a change of the value cumbersome. Even if the value is used in one program location only, advantages over just putting the value there are that the name of the constant can be informative about its meaning, and the value is specified at a more convenient standard location in the program, such as at the beginning.
=== Variables names ===
Variables are denoted by identifiers.
In some languages, specific characters are prepended or appended to variable identifiers to indicate the variable's type. For example:
* in BASIC programming language, the suffix $ on a variable name indicates that its value is a String_%28computer_science%29;
* in Perl, the prefixes $, @, %, and & indicate scalar, array, hash, and subroutine variables, respectively.
The identifier article describes cases where the actual identifier itself, rather than a prefix or suffix, is interpreted by the compiler or interpreter.
See also:
* namespaces (computer science)
=== Scope and extent ===
The ''scope'' and ''extent'' (or ''lifetime'') of a variable describe where in the program's text it may be used, and when in the program's execution it has a value.
In most languages, variables can have different ''Scope (programming)''. The scope of a variable is the portion of the program code for which the variable's name has meaning. For instance, a variable with ''lexical scope'' is meaningful only within a certain block of statements or subroutine. A ''global variable'', or one with ''indefinite scope'', may be referred to anywhere in the program. When a variable has gone out of scope, it is erroneous or meaningless to refer to it. Lexical analysis of a program can determine whether variables are used out of scope.
Likewise, the binding (computer science)s of variables to values can have different ''extent''. The extent of a binding is the length of time -- part of the course of the program's execution -- during which the variable continues to refer to the same value or place. A running program may enter and leave a given extent many times, as in the case of a closure. A variable can be ''unbound'', meaning that it is in scope but has never been given a value, or its value has been destroyed; in many languages, it is an error to try to use the value of an unbound variable, or may yield unpredictable results.
In other words, scope is a lexical fact, but extent a runtime (dynamic) fact. If a variable name is out of scope, then it is an error for that name to be used in the program code. In compiled languages, this error can be detected statically at compile-time. If a variable is out of extent, its value cannot be referred to (since it doesn't have one; it is unbound) but it may be given a value, which gives it a new extent.
When a variable binding extends (in time) as the program's execution passes out of the variable's scope, this is no bug. It is a Lisp closure or a C static variable: when execution passes back into the variable's scope, the variable may be referred to again. But when a variable's extent ends, it becomes unbound -- if it is still in scope, referring to it is an error (or, in C, gets you a nice arbitrary value).
It is considered good programming practice to make variables as narrow a scope as feasible so that different parts of a program do not accidentally interact with each other by modifying each other's variables. This also prevents action at distance (computer science). Common techniques for doing so are to have different sections of your program use different Namespace_%28programming%29s, or else make individual variables private through either dynamic variable scoping or lexical variable scoping.
Many programming languages employ a reserved value (often named null or nil) to indicate an invalid or uninitialized variable.
=== Memory allocation ===
Bound variables have values. A value, however, is an abstraction, an idea; in implementation, a value is represented by some ''data object'', which is stored somewhere in computer memory. The program, or the runtime environment, must set aside memory for each data object and, since memory is finite, ensure that this memory is yielded for re-use when the object is no longer needed to represent some variable's value.
The handling of memory for variables is highly dependent on the programming language environment. Many language implementations handle the simplest cases easily by distinguishing those variables whose extent lasts no longer than a single function call. Space for these ''local variables'' are allocated on the ''execution stack'', where their memory is automatically reclaimed when the function returns.
Space for other objects must be allocated on the ''heap'', or pool of unused memory. These must be reclaimed specially when the objects are no longer needed. In a ''garbage collection (computer science)'' (gc) language such as Java or Lisp, the runtime environment automatically "reaps" objects when it can be proven that no extant variable refers to them. In a ''non-gc'' language such as C, it is up to the program (and thus the programmer) to explicitly malloc memory; and in turn to state when memory can be reclaimed, by explicitly freeing it. Failure to do so leads to memory leaks, in which the heap is depleted over the program's run. If the program runs long enough, it will exhaust available memory and fail.
Memory allocation goes beyond single variables. A variable may refer to a data structure created dynamically, where many structure components are not ''directly'' named by variables, but are reachable from a variable by traversing the structure. For this reason, garbage collectors (and programs in languages which lack them) must deal with the case where a ''portion'' of the memory reachable from a variable needs to be reclaimed.
=== Typed and untyped variables ===
In static typing languages such as Java programming language or ML programming language, a variable also has ''type'', meaning that only values of a given sort can be stored in it. In dynamic typing languages such as Python programming language or Lisp programming language, it is values and not variables which carry type. ''See type system.''
Typing of variables also allows polymorphism (computer science) to be resolved at compile time.
=== Parameters ===
The ''arguments'' or ''formal parameters'' of functions are also referred to as variables. For instance, in these equivalent functions in Python and Lisp
def addtwo(x):
return x + 2
(defun addtwo (x) (+ x 2))
the variable named x is an argument. It is given a value when the function is called. In most languages, function arguments have local scope; this specific variable named x can only be referred to within the addtwo function, though of course other functions can also have variables called x.
==External link==
*[http://www.legislation.hmso.gov.uk/acts/acts2003/30042--b.htm Example of the use of variables (persons A and B) in a law] (NB: this comes from the Sexual Offences Act.)
Algebra
Elementary mathematics
vi:Biến sốVariableI made some changes to the "Names of variables" section: * The section discussed many attributes that belonged in the identifier article. I've reworded and moved a few paragraphs (for example about naming conventions and Lisp symbols) for that reason. * I replaced the discussion of namespaces by a link to the namespace (computer science) article. * Changed the section name to "variable names". -- User:Eelis.net 01:17, 2005 May 23 (UTC) ----- I think the text in the "Computer programming" section of [http://en.wikipedia.org/w/wiki.phtml?title=Variable&oldid=4928052 this revision] is much more clear and readable than the current text. It is far from perfect but the current text has a lot of bad English and ambiguous sentences, and uses erratic terms, such as "life-time" in place of the standard term "extent". I think it is a better place to work from than the current text. I'd revert -- but I wrote much of the old text and am certainly biased. Anyone else watching? --User:Fubar Obfusco 05:30, 1 Aug 2004 (UTC) :It's been almost two weeks with no comment, so I'm restoring several paras of the older version, somewhat improved and better laid-out. --User:Fubar Obfusco 12:17, 10 Aug 2004 (UTC) :I think it is a matter of perference. I replaced the old text by a new one for the same reason the old text uses unheard term like ''extent'' instead of life-time and is rather unorgainzed and spending too much on somehow irrelevant topics like scoping. There is an article about scope so this article should not spend too much on it. Particularly, the article is making a wrong impression about storage. The key to understand variables is binding. Scopes merely help binding and unbinding process. GC, for instance, has nothing to do with variables. Objects that are not realized by any variable could exist and can be reclamied or not. I believe the new one is far clear on this matter. True, I have removed some parts in the old text so later I will try to merge them into one. -- User:TakuyaMurata 03:07, Aug 21, 2004 (UTC) ::While I respect your views, I do not believe they are representative of the field we are discussing. The terms ''scope and extent'' are in standard use in computer science. [http://www.cs.man.ac.uk/~pjj/cs2111/ho/node14.html] [http://www.dcs.warwick.ac.uk/~john/jade/jade_145.html] [http://www.supelec.fr/docs/cltl/clm/node43.html] [http://tinuviel.cs.wcu.edu/~shults/Spring2003/CS151/handouts/Scope.html] The term "lifetime" (not "life-time") is sometimes used as a synonym for "extent", but Google searches suggest it is less common. ::You have eradicated several paragraphs of useful discussion of scope and extent, of typed and untyped variables, of function parameters, and storage of variables. While you may believe these are not relevant, they are most certainly related in computer science literature. Garbage collection, for instance, has substantial effects on the way programmers use variables. ::I agree with you on the importance of the concept of ''binding''. Please consider working this in to the larger, more complete text rather than deleting wholesale sections that I and others have written. I am restoring the deleted material in parallel with your text. I will be soliciting comment from others who have edited this article recently on how the two can be reconciled. --User:Fubar Obfusco 01:29, 27 Aug 2004 (UTC) I have heard both terms ''lifetime'' and ''extent'' used for variables. I don't think one is particularly more clear than the other, but perhaps they both should be mentioned the first time. I may try to work on the phrasing there, but the english in that whole paragraph is a mess. ("life-time" is a mispelling IMHO.) Also, I think scope should be described in terms of binding, as scope and extent are only related for the special case of local variables, and are not related when refering to static variables, global variables, dynamic variables, class variables, etc... This paragraph is really just a disorganized jumble of concepts. The concepts of scope, lifetime, binding, gc'ing, etc., all need to be defined each in their own paragraph before you try to relate them and mix them together. I think it is very helpful, however, to include (limited) examples of languages that use each technique. The concept of Garbage collection (vs. malloc/free) is extremley important. C and assembly programmers will not survive until they understand these things and how they relate to the lifetime of a variable, which may exceed its scope or may be exceeded by its scope. (I.e., passing a reference to a variable that is about to die is a bug. Allowing a reference to go out of scope without freeing its target (and thus ending its lifetime) is a different bug.) Does extent apply to a length of (run)time, a length of code, or both? This needs to be clarified. --User:Ssd 03:31, 27 Aug 2004 (UTC) :I think this quote from Guy L. Steele's ''Common Lisp: the Language'' describes the interplay between scope and extent well: :''[T]he notions of ''scope'' and ''extent'' are frequently useful. These notions arise when some object or construct must be referred to from some distant part of a program. Scope refers to the spatial or textual region of the program within which references may occur. Extent refers to the interval of time during which references may occur.'' [http://www.supelec.fr/docs/cltl/clm/node43.html] :In other words, scope is a lexical fact, but extent a runtime (dynamic) fact. I would go so far as to say that scope has to do with names, extent with bindings of variables to values, and memory allocation with values (or rather, data objects that represent values). If a name is out of scope, you can't even bind it; if it is out of extent, you can't refer to it ''except'' to bind it, which gives it a new extent; if its value is still taking up memory when it's out of extent, it's a leak (in C) or garbage (in Java or Lisp). :When a variable binding extends (in time) as the program's execution passes out of the variable's scope, this is no bug. It is a Lisp closure or a C static variable: when execution passes back into the variable's scope, the variable may be referred to again. But when a variable's extent ends, it becomes unbound -- if it is still in scope, referring to it ''is'' an error (or, in C, gets you a nice arbitrary value). :Extent is related to memory reclamation. When a variable becomes unbound, if its value is occupying storage it must be reclaimed. This is where memory allocation (be it manual or automatic) comes in. In a non-gc system like C, it is a memory leak bug when an object (a data representation of a value) continues to take up storage after no more variables are bound to it. In a gc system like Java or Lisp, it is no bug; the gc reclaims the storage. --User:Fubar Obfusco 04:57, 27 Aug 2004 (UTC) ::Heh, now to incorporate that nice description into the article... --User:Ssd 00:06, 29 Aug 2004 (UTC) ---- I think there needs to be a more clearly defined seperation between variables in CS and variables in mathematics - there is a quite distinct treatment of the two. Perhaps the section for CS can look something like Operator - cover a short paragraph or two on the important topics and leave the important treatment to the respective articles? User:Dysprosia 11:58, 31 Aug 2004 (UTC) ---- Hello. I wonder about the reference to Help:Variable in this article. I'm not in favor of self-references within WP but I can see that someone might easily come here looking for special wiki variables. Suggestions? Regards & happy editing, User:Wile E. Heresiarch 15:57, 25 Jan 2005 (UTC) VariableThis is a list of variables that can be used in the wikitext. The way they are rendered depends on the time, on the project, or on the page in which it occurs. On the left is the variable, on the right how it is rendered at this time, in this project, on this page. ==Constant, only depending on the project and parameters==
VariableThis is a talk page. Why is making a link like this: low-frequency radarlow-frequency radar better than this? low-frequency radarslow-frequency radars Seems to me they have the same effect but the latter leads to smaller pages which is better for the databases etc. User:Nvinen 02:16, 11 Feb 2005 (UTC) Then change it.User:Variable 19:11, 11 Feb 2005 (UTC) OK, I was just wondering if there was a reason for you changing it into the other format. I thought maybe someone had told you that was how it should be done etc. I didn't want to change it back if you had a reason for doing it. User:Nvinen 01:39, 12 Feb 2005 (UTC) ==Republik Maluku Selatan== I kind of figured I would get that question. I'll answer it at Talk:South Moluccas. User:Kevintoronto 19:21, 1 Apr 2005 (UTC) ==Autonomist movements== Thanks for your comments. I have deleted the ones identified previously, and posted an additional list of candidates for deletion at Talk:List of active autonomist and secessionist movements. User:Ground Zero 19:45, 13 Apr 2005 (UTC) ==Cabinda== Hi... sorry about taking so long to respond. I've uploaded a new locator map for Angola which should now show Cabinda. I hope it's satisfactory. -- User:Vardion 22:03, 18 Apr 2005 (UTC) == AMA Meeting Proposal == Hi! I put together a [http://en.wikipedia.org/wiki/Wikipedia:AMA_Meeting_%28suggested_topics%29#New_Membership_Meeting_Call proposal for another AMA meeting] that I'm hopeful you can chime in on. --User:Wgfinley 20:10, 25 Apr 2005 (UTC) ---- Nokia's Culture What I have written here which you deleted is true based on my experiences. If you're familiar with the country, you will discover that the Finnish people are very proud of their accomplishments; such as Nokia. I don't believe one can separate the company's culture from the country's national pride. I know because some of these Nokians are like family. The information I provided is not found in any news article or press release. You won't find it there...then on the flip side, it's the same as where's the proof that what I contributed here is false? User:Ariele 01:27, 13 May 2005 (UTC) ::What is the principle of NPOV? By the way, the readers may not be familiar with the abbreviated term NPOV? Upon first seeing it, it sounds Russian but I know it isn't Russian. Does that apply also to the theory of relativity? It is afterall just a theory and has not been proven as law. But you have a valid argument as well. I have considered the idea of contacting some of my Finnish acquaintances for their feedback. User:Ariele 17:55, 18 May 2005 (UTC) == My RFA == Thank you for supporting my RFA. User:Guettarda 00:14, 21 Jun 2005 (UTC) :Thank yourself. You had to do the good work, all I did was recognize it. User:Variable 03:23, 21 Jun 2005 (UTC) ==Revision3 Studios== Hi. I noticed that you voted to keep the ''Systm'' article on Wikipedia:Votes_for_deletion/Systm. Well, unfortunately, the article was deleted, and ''Systm'' was redirected to Kevin Rose. I recently created a new article for Revision3 Studios, the company that produces ''System'' and ''thebroken'', and changed ''Systm'' to redirect there. Unfortunately, the Revision3 Studios article has now been nominated for deletion. So, if you have a chance, please look at the Revision3 Studios article, and then go to Wikipedia:Votes for deletion/Revision3 Studios and vote to keep it. Thanks a lot, --User:Taestell 17:01, Jun 22, 2005 (UTC) == Note == Hi ! you left a note on my talk page regarding the "minor edit" issue I understand what you mean sometimes it happens with the speed and flow of work you are in and not able to see and ususally overlook minor things but thanx for pointing it out.Let it be known that it was not deliberate.--User:Awais141 00:17, 23 Jun 2005 (UTC) I came back to talk to you about the lines that are POV and you restored them .Can you please verrify such BBC reporting on that Issue?? if not I recommend deletion just by saying that such and such was a fact does not mean its true,but I am still certain you will come up with some proof so I will make no changes till then.--User:Awais141 00:38, 23 Jun 2005 (UTC) :I'll take this up on the talk page for Military of Pakistan. User:Variable 02:58, 23 Jun 2005 (UTC) VariableThis is a user page. Don't expect it to be too meaningful. Variable#REDIRECT Help:Variable See other meanings of words starting from letter: VWords begining with Variable: Variable Variable Variable Variable Variable Variable Variable-binding_operation Variable-binding_operator Variable-capacitors.agr.jpg Variable-Frequency_Drive Variable-frequency_drive Variable-geometry Variable-width_encoding Variables Variables Variables Variable_(computer_science) Variable_Air_Duct Variable_area_meter Variable_argument_macro Variable_binding_operation Variable_binding_operator Variable_binding_operator Variable_Bit_Rate Variable_bit_rate Variable_bit_rate Variable_Cam_Timing Variable_cam_timing Variable_capacitance_diode Variable_capital Variable_cost Variable_costs Variable_Cylinder_Management Variable_Data_Intelligent_Postscript_Printware Variable_Data_Printing Variable_declaration Variable_displacement Variable_displacement_pump Variable_displacement_pump Variable_fighter Variable_fighters Variable_frame_rate Variable_Frequency_Drive Variable_Frequency_Oscillator Variable_geometry_Europe Variable_Geometry_Self-Propelled_Battle_Droid Variable_geometry_wing Variable_Information_Printing Variable_intake Variable_Intake_Control_System Variable_length_buffer Variable_Length_Intake_Manifold Variable_length_intake_manifold Variable_length_subnet_mask Variable_line_demo Variable_line_demo Variable_Message_Sign Variable_message_sign Variable_message_signs Variable_number_tandem_repeats Variable_platyfish Variable_pricing Variable_rate_encoding Variable_rate_mortgage Variable_resistor Variable_Resonance_Induction_System Variable_returns_to_scale Variable_scoping Variable_Skink Variable_skink Variable_specific_impulse_magnetoplasma_rocket Variable_specific_impulse_magnetoplasma_rocket Variable_speed_of_light Variable_speed_of_light Variable_star Variable_star Variable_stars Variable_stars Variable_star_designation Variable_substitution Variable_Sunbird Variable_sunbird Variable_text_demo Variable_transmission_Dacia Variable_Tumble_Control_System Variable_Universal_Life_Insurance Variable_Universal_Life_Insurance Variable_universal_life_insurance Variable_universal_life_insurance Variable_Valve_Timing Variable_valve_timing Variable_valve_timing |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
These materials are based on Wikipedia and licensed under the GNU FDL
YouTube.com videos better site than Turbo Tax 2007 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|