/usr/share/doc/octave/octave.html/Global-Variables.html is in octave-doc 4.2.2-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Global Variables (GNU Octave)</title>
<meta name="description" content="Global Variables (GNU Octave)">
<meta name="keywords" content="Global Variables (GNU Octave)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<link href="index.html#Top" rel="start" title="Top">
<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Variables.html#Variables" rel="up" title="Variables">
<link href="Persistent-Variables.html#Persistent-Variables" rel="next" title="Persistent Variables">
<link href="Variables.html#Variables" rel="prev" title="Variables">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smalllisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>
<link rel="stylesheet" type="text/css" href="octave.css">
</head>
<body lang="en">
<a name="Global-Variables"></a>
<div class="header">
<p>
Next: <a href="Persistent-Variables.html#Persistent-Variables" accesskey="n" rel="next">Persistent Variables</a>, Up: <a href="Variables.html#Variables" accesskey="u" rel="up">Variables</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<a name="Global-Variables-1"></a>
<h3 class="section">7.1 Global Variables</h3>
<a name="index-global-variables"></a>
<a name="index-global-statement"></a>
<a name="index-variables_002c-global"></a>
<p>A variable that has been declared <em>global</em> may be accessed from
within a function body without having to pass it as a formal parameter.
</p>
<p>A variable may be declared global using a <code>global</code> declaration
statement. The following statements are all global declarations.
</p>
<div class="example">
<pre class="example">global a
global a b
global c = 2
global d = 3 e f = 5
</pre></div>
<p>A global variable may only be initialized once in a <code>global</code>
statement. For example, after executing the following code
</p>
<div class="example">
<pre class="example">global gvar = 1
global gvar = 2
</pre></div>
<p>the value of the global variable <code>gvar</code> is 1, not 2. Issuing a
‘<samp>clear gvar</samp>’ command does not change the above behavior, but
‘<samp>clear all</samp>’ does.
</p>
<p>It is necessary declare a variable as global within a function body in
order to access it. For example,
</p>
<div class="example">
<pre class="example">global x
function f ()
x = 1;
endfunction
f ()
</pre></div>
<p>does <em>not</em> set the value of the global variable <code>x</code> to 1. In
order to change the value of the global variable <code>x</code>, you must also
declare it to be global within the function body, like this
</p>
<div class="example">
<pre class="example">function f ()
global x;
x = 1;
endfunction
</pre></div>
<p>Passing a global variable in a function parameter list will
make a local copy and not modify the global value. For example, given
the function
</p>
<div class="example">
<pre class="example">function f (x)
x = 0
endfunction
</pre></div>
<p>and the definition of <code>x</code> as a global variable at the top level,
</p>
<div class="example">
<pre class="example">global x = 13
</pre></div>
<p>the expression
</p>
<div class="example">
<pre class="example">f (x)
</pre></div>
<p>will display the value of <code>x</code> from inside the function as 0,
but the value of <code>x</code> at the top level remains unchanged, because
the function works with a <em>copy</em> of its argument.
</p>
<a name="XREFisglobal"></a><dl>
<dt><a name="index-isglobal"></a>: <em></em> <strong>isglobal</strong> <em>(<var>name</var>)</em></dt>
<dd><p>Return true if <var>name</var> is a globally visible variable.
</p>
<p>For example:
</p>
<div class="example">
<pre class="example">global x
isglobal ("x")
⇒ 1
</pre></div>
<p><strong>See also:</strong> <a href="Variables.html#XREFisvarname">isvarname</a>, <a href="Status-of-Variables.html#XREFexist">exist</a>.
</p></dd></dl>
<hr>
<div class="header">
<p>
Next: <a href="Persistent-Variables.html#Persistent-Variables" accesskey="n" rel="next">Persistent Variables</a>, Up: <a href="Variables.html#Variables" accesskey="u" rel="up">Variables</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>
|