Jump to content

Undefined variable

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by File Not Found (talk | contribs) at 03:16, 8 February 2006 (examples). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

An undefined variable in a computer program is a variable name that is called by the program but which has not been previously assigned a value by that program. This usually results in an undefined variable error message.

Examples

Each code example is followed by an error message.

Perl 5.8:

use strict;
my $y = $x;

Global symbol "$x" requires explicit package name at foo.pl line 2.
Execution of foo.pl aborted due to compilation errors.

Python 2.4:

 x = y

Traceback (most recent call last):
  File "foo.py", line 1, in ?
    x = y
NameError: name 'y' is not defined

JavaScript (Mozilla Firefox 1.0):

 y = x

 Error: x is not defined
 Source File: file:///c:/temp/foo.js

GNU CLISP 2.35:

(setf y x)

*** - EVAL: variable X has no value