Special variables: Difference between revisions

m
syntax highlighting fixup automation
m (→‎j special local variables: take advantage of decimal number visual pun in examples)
m (syntax highlighting fixup automation)
Line 31:
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-1.18.0/algol68g-1.18.0-9h.tiny.el5.centos.fc11.i386.rpm/download 1.18.0-9h.tiny].}}
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d] - due to extensive use of '''format'''[ted] ''transput''.}}
<langsyntaxhighlight lang="algol68">#!/usr/local/bin/a68g --script #
 
FORMAT f = $g": ["g"]"l$;
Line 86:
END CO
));
SKIP</langsyntaxhighlight>
Sample output:
<pre>
Line 125:
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d] - due to extensive use of '''format'''[ted] ''transput''.}}
[[ALGOL 68G]] provides some further constants to the scientifically motivated coder:
<langsyntaxhighlight lang="algol68">#!/usr/local/bin/a68g --script #
 
printf(($g": [", g, "] & [",g,"]"l$,
Line 239:
" joule", mksa joule, cgs joule,
" erg", mksa erg, cgs erg
))</langsyntaxhighlight>
Output:
<pre>
Line 356:
 
=={{header|ALGOL W}}==
<langsyntaxhighlight lang="algolw">% the Algol W standard environment includes the following standard variables: %
 
integer I_W % field width for integer output %
Line 400:
if the relevant EXCEPTION variable is null, the exception is ignored,
otherwise it is processed according to the settings of XCPLIMIT etc.
%</langsyntaxhighlight>
 
=={{header|Arturo}}==
Line 512:
Besides <code>errno</code> like C, C++ has the <code>this</code> pointer so objects can refer to themselves.
 
<langsyntaxhighlight lang="cpp">#include <iostream>
 
struct SpecialVariables
Line 536:
auto sv2 = ++sv; // makes a copy of sv after it was incremented
std::cout << " sv :" << sv.i << "\n sv2:" << sv2.i << "\n";
}</langsyntaxhighlight>
{{out}}
<pre>
Line 545:
=={{header|Clojure}}==
The following snippet prints a list of the special variables defined in clojure.core, in *earmuff* form. For further information, consult the [http://clojuredocs.org/quickref/shortdesc/Clojure%20Core documentation].
<langsyntaxhighlight lang="clojure">
(apply str (interpose " " (sort (filter #(.startsWith % "*") (map str (keys (ns-publics 'clojure.core)))))))
</syntaxhighlight>
</lang>
{{Out}}
<pre>*1 *2 *3 *agent* *allow-unresolved-vars* *assert* *clojure-version* *command-line-args* *compile-files* *compile-path*
Line 559:
 
The following code snippet prints a list of all 44 special variables defined by the Common Lisp standard. For further information about each of them consult the [http://www.lispworks.com/documentation/HyperSpec/Front/X_Alph_9.htm online documentation].
<langsyntaxhighlight lang="lisp">(defun special-variables ()
(flet ((special-var-p (s)
(and (char= (aref s 0) #\*)
Line 570:
lst)))
 
(format t "~a~%" (sort (special-variables) #'string<))</langsyntaxhighlight>
 
{{Out}}
Line 637:
Dyalect has a special <code>this</code> which is available inside methods:
 
<langsyntaxhighlight lang="dyalect">func Integer.Double() {
this + this
}
print(8.Double())</langsyntaxhighlight>
 
=={{header|Déjà Vu}}==
Line 648:
call for pass</pre>
In addition, <code>eva</code> is special:
<langsyntaxhighlight lang="dejavu">!print "hey" #is really short for
eva!print "hey"</langsyntaxhighlight>
EVA is the part of the standard library that takes care of communication with the outside world. It makes extensive use of the method call syntax, unlike the rest of the standard library, that is why it is special.
 
Line 655:
Erlang has no special variables.
What it does have are special functions, module_info/0 and module_info/1. These are added to a module automatically, without being present in the code.
<syntaxhighlight lang="erlang">
<lang Erlang>
-module( special_variables ).
 
Line 661:
 
task() -> ok.
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 712:
Fortran offers no special variables such as Pi, e, etc. as a part of the language, not even the modern special floating-point "values" such as NaN. Indeed, the syntax has no reserved words generally so that <code>GO TO</code> could be the name of a variable without damage to GO TO statements, though it is generally agreed that calling a variable END is provocative... It does have some ''numbers'' that are special: 5 is the input/output "unit number" for keyboard input and 6 for output to "standard output", the screen on desktop computers; in the past there have been other values that were associated to devices such as the card reader, card punch, lineprinter, paper tape reader, and so on at any given installation. But these constants are not given names as mnemonics for their special values, except by the programmer. There is no equivalent of SYSOUT as in WRITE(SYSOUT,''etc'' without definition by the programmer.
 
Certain statements involve special names in what appear to be assignments of values to or from a special name that has a value just like a named variable does, but these are ''not'' proper variables at all. For instance, in <langsyntaxhighlight Fortranlang="fortran"> INQUIRE(FILE = FILENAME(1:L),EXIST = EXIST, !Here we go. Does the file exist?
1 ERR = 666,IOSTAT = IOSTAT) !Hopefully, named in good style, etc.
IF (EXIST) THEN !So, does the named file already exist?
...etc.</langsyntaxhighlight>
ERR is a special name, but only inside the context of the INQUIRE (and OPEN, and WRITE, ''etc.'') statement, it is not the name of an existing variable outside that statement whether defined by the language or by the programmer, and if the programmer were to define a variable called ERR it would have no relevance within that INQUIRE statement - though <code>ERR = ERR</code> ''would'' be workable if an ASSIGN statement had assigned statement label 666 to variable ERR. Similarly, the variable named FILENAME is declared by the programmer and because there are no reserved words, could be just FILE. Likewise, EXIST is declared (as LOGICAL) and IOSTAT (as INTEGER) as a mnemonic aid and also to save on the trouble of remembering whether the assignment works left-to-right or right-to-left in each case. It is right-to-left for FILE = ''filename'', input to the INQUIRE statement and left-to-right for EXIST = ''variable'', an output of the INQUIRE statement.
 
Line 731:
=={{header|Icon}} and {{header|Unicon}}==
Icon and Unicon have special variables known as keywords which are syntactically are preceded by an &.
<syntaxhighlight lang="unicon">
<lang Unicon>
# &keyword # type returned(indicators) - brief description
# indicators:
Line 808:
&y # integer(=G) - pointer vertical position
# keywords may also fail if the corresponding feature is not present.
# Other variants of Icon (e.g. MT-Icon) will have different mixes of keywords.</langsyntaxhighlight>
 
=={{header|IS-BASIC}}==
<langsyntaxhighlight ISlang="is-BASICbasic">BLACK - The code of colour black.
BLUE - The code of colour blue.
CYAN - The code of colour cyan.
Line 826:
WHITE - The code of colour white.
YELLOW - The code of colour yellow.
VERNUM - Version number of the BASIC</langsyntaxhighlight>
 
=={{header|J}}==
Line 844:
 
Some examples:
<langsyntaxhighlight Jlang="j"> {{ y }} 1
1
1000 {{ x + y }} 1
Line 859:
1011
(1000) 100 {{ x v m v y }} + (1)
1101</langsyntaxhighlight>
 
These names may be used as regular names, but that is bad practice except in the context of debugging or illustration.
Line 1,021:
Inside an object there is <code>this</code>, a reference that points to the object itself (like 127.0.0.1 in networking) and are used to qualify member access. There is also <code>super</code> that does the same for the base class (actually "the next class in the inheritance tree"). Both are not demonstrated in the example below.
 
<langsyntaxhighlight Javalang="java">import java.util.Arrays;
 
public class SpecialVariables {
Line 1,052:
}
 
</syntaxhighlight>
</lang>
 
=={{header|JavaScript}}==
Line 1,058:
<code>this</code> evaluates to the object the immediately enclosing function was called on as a method, if it was. If it was not called as a method, <code>this</code> is either the global environment object (usually <code>window</code> in browsers) in non-strict mode, or <code>undefined</code> in strict mode. <code>this</code> is an expression resembling a variable, but not actually a variable; for example, it is a syntax error to assign to it.
 
<langsyntaxhighlight lang="javascript">var obj = {
foo: 1,
bar: function () { return this.foo; }
};
obj.bar(); // returns 1</langsyntaxhighlight>
 
When a function is entered, the ''variable'' <code>arguments</code> is bound to an “arguments object” which is an array-like object containing the function's arguments, as well as some other information. This how [[varargs]] functions are implemented in JavaScript. If the function's parameters contain “<code>arguments</code>” explicitly, then it is ''not'' overridden and functions as an ordinary parameter.
 
<langsyntaxhighlight lang="javascript">function concat() {
var s = "";
for (var i = 0; i < arguments.length; i++) {
Line 1,073:
return s;
}
concat("a", "b", "c"); // returns "abc"</langsyntaxhighlight>
 
=={{header|jq}}==
Variables in jq are identifiers preceded by the sigil "$", e.g. <code>$x</code>. There are no predefined variables, but jq does allow variables to be assigned string values on the command line.
 
For example:<langsyntaxhighlight lang="sh">$ jq -n -M --arg x 1 '$x|type' # (*)
"string"</langsyntaxhighlight>
(*) Windows users would write "$x|type".
 
=={{header|Julia}}==
Julia starts with the <code>Base</code> module loaded. Taking "special variables" to mean names in the default global namespace (<code>Base</code>) that aren't functions, types, or modules, then you can obtain them with
<langsyntaxhighlight lang="julia">join(sort(filter(sym -> let n=eval(sym); !(isa(n, Function) || isa(n, Type) || isa(n, Module)); end, names(Base))), ", ")</langsyntaxhighlight>
{{out}}
<pre>":, ARGS, CPU_CORES, C_NULL, DL_LOAD_PATH, DevNull, ENDIAN_BOM, ENV, I, Inf, Inf16, Inf32, InsertionSort, JULIA_HOME, LOAD_PATH, MS_ASYNC, MS_INVALIDATE, MS_SYNC, MergeSort, NaN, NaN16, NaN32, OS_NAME, QuickSort, RTLD_DEEPBIND, RTLD_FIRST, RTLD_GLOBAL, RTLD_LAZY, RTLD_LOCAL, RTLD_NODELETE, RTLD_NOLOAD, RTLD_NOW, RoundDown, RoundFromZero, RoundNearest, RoundToZero, RoundUp, STDERR, STDIN, STDOUT, VERSION, WORD_SIZE, catalan, cglobal, e, eu, eulergamma, golden, im, pi, γ, π, φ"</pre>
Line 1,098:
 
The following program illustrates their usage:
<langsyntaxhighlight lang="scala">// version 1.0.6
 
class President(val name: String) {
Line 1,121:
val pres3 = President("Theodore")
pres3.age = 158
}</langsyntaxhighlight>
 
{{out}}
Line 1,137:
In Lasso parameters can be referenced as numerical locals within methods or unbound captures. [http://lassoguide.com/language/variables.html?#parameter-pseudo-locals]
 
<langsyntaxhighlight Lassolang="lasso">{return #1 + ':'+#2}('a','b') // a:b</langsyntaxhighlight>
 
<langsyntaxhighlight Lassolang="lasso">define test(a,b) => #1+':'+#2
test('y','z') // y:z</langsyntaxhighlight>
 
=={{header|Lingo}}==
Line 1,170:
 
Further to those, LiveCode comes with a plethora of built-in constants, which are readily listed with the following command:
<langsyntaxhighlight LiveCodelang="livecode">put the constantNames</langsyntaxhighlight>It also provides colours as built-ins, accessible through <langsyntaxhighlight LiveCodelang="livecode">the colornames</langsyntaxhighlight> You can search the dictionary in the IDE using text "names" to discover more such as the ''propertyNames'' & the ''commandNames'', though are not strictly pertinent to this task.
 
=={{header|Lua}}==
Line 1,180:
To list all global variables:
 
<langsyntaxhighlight lang="lua">for n in pairs(_G) do print(n) end</langsyntaxhighlight>
 
The list will include built-in global functions, whose availability depends on the implementation and compile time configuration.
Line 1,189:
All identifiers can be change to be used as variables, using a dot. For modules/functions in a group we have to define these variables using a dot.
 
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module Checkit {
Let inkey$="hello", dir$="Something Else"
Line 1,220:
Check3
 
</syntaxhighlight>
</lang>
 
 
Line 1,238:
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">Grid[Partition[Names["$*"],4]]
->
$Aborted $ActivationGroupID $ActivationKey $ActivationUserRegistered
Line 1,282:
$TimeZone $TopDirectory $TraceOff $TraceOn
$TracePattern $TracePostAction $TracePreAction $Urgent
$UserAddOnsDirectory $UserBaseDirectory $UserBasePacletsDirectory $UserDocumentsDirectory</langsyntaxhighlight>
 
=={{header|Maxima}}==
<langsyntaxhighlight lang="maxima">/* There are many special variables in Maxima: more than 250 are used for options, for example */
fpprec; /* precision for big floats */
obase; /* number base for output */
Line 1,291:
/* Other variables are read-only, and give the list of user-defined variables, functions... */
infolists; /* give the names of all available lists */
[labels, values, functions, macros, arrays, myoptions, props, aliases, rules, gradefs, dependencies, let_rule_packages, structures]</langsyntaxhighlight>
 
=={{header|MIPS Assembly}}==
When multiplying two registers, the product is always stored in the <code>$HI</code> and <code>$LO</code> registers. Their contents can be read into your standard registers with the commands <code>mfhi $reg</code> and <code>mflo $reg</code>.
 
<langsyntaxhighlight lang="mips">
li $t0,0x4500
li $t1,0xFFFF
multu $t0,$t1 ;unsigned multiplication of $t0 and $t1
mfhi $t0 ;load the top 32 bits of the product into $t0
mflo $t1 ;load the bottom 32 bits of the product into $t1</langsyntaxhighlight>
 
Division is a similar story, except <code>$HI</code> holds the remainder and <code>$LO</code> holds the quotient.
Line 1,309:
=={{header|ML/I}}==
===Input===
<langsyntaxhighlight MLlang="ml/Ii">MCSKIP "WITH" NL
"" Special variables
"" There are four different kinds of variables in ML/I.
Line 1,340:
All other S-variables have implementation defined meanings.
>
SVARDEMO</langsyntaxhighlight>
 
===Output===
<langsyntaxhighlight MLlang="ml/Ii">T-variables are local to the current macro call
T1 is the number of arguments to current macro call - value is 2
T2 is the number of macro calls so far - value is 5
Line 1,357:
S7, S8 and S9 are currently unused.
 
All other S-variables have implementation defined meanings.</langsyntaxhighlight>
 
=={{header|Nanoquery}}==
Nanoquery has a number of immutable special variables which can be listed by executing the following program:
<syntaxhighlight lang ="nanoquery">println dumpstack()</langsyntaxhighlight>
{{out}}
<pre>{{dbsize, 0}, {col, 1}, {workingdir, C:\Users\Will\Programs\Nanoquery}, {false, false}, {interactive, false}, {main, true}, {packages, [, Nanoquery.Objects, Nanoquery.Exceptions]}, {libpath, C:\Users\Will\Programs\Nanoquery\nanoquery-2.3_1866}, {args, [-b, rosetta-code/specialvars.nq]}, {rec, 1}, {filename, }, {null, null}, {__file__, C:\Users\Will\Programs\Nanoquery\rosetta-code\specialvars.nq}, {true, true}, {prompt, [\S | rec\R col\C] % }, {cols, 0}, {lockedfiles, []}, {__calls__, [<global>:1]}}</pre>
Line 1,395:
<code>'''ask''', '''class''', '''digits''', '''form''', '''length''', '''null''', '''source''', '''sourceline''', '''super''', '''this''', '''trace''', '''version'''</code>.
 
<langsyntaxhighlight NetRexxlang="netrexx">/* NetRexx */
options replace format comments java crossref savelog symbols binary
 
Line 1,429:
 
return
</syntaxhighlight>
</lang>
;Output
<pre>
Line 1,455:
 
In Nim, there is only one special variable, named <code>result</code>. It is implicitly declared in procedure which returns a result and is initialized with binary zeroes. Statement <code>return value</code> is in fact a shortcut for:
<langsyntaxhighlight Nimlang="nim">result = value
return</langsyntaxhighlight>
 
There are also variables declared in modules and exported. As some modules are implicitly imported, their exported variables are automatically visible. Modules implicitly imported are: “system” (which imports “iterators”, “assertions”, “dollars”, “io” and “widestr”), “threads” and “channels”, the latter two being activated if option <code>--thread:on</code> is used.
Line 1,475:
Some predefined variables from the <code>[http://caml.inria.fr/pub/docs/manual-ocaml/libref/Sys.html Sys]</code> module:
 
<langsyntaxhighlight lang="ocaml">val argv : string array
(** The command line arguments given to the process.
The first element is the command name used to invoke the program.
Line 1,512:
where [major], [minor], and [patchlevel] are integers, and
[additional-info] is an arbitrary string. The [[.patchlevel]] and
[[+additional-info]] parts may be absent. *)</langsyntaxhighlight>
 
Some predefined variables from the <code>[http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html Pervasives]</code> module:
 
<langsyntaxhighlight lang="ocaml">val max_int : int
(** The greatest representable integer. *)
 
Line 1,530:
val epsilon_float : float
(** The difference between [1.0] and the smallest exactly representable
floating-point number greater than [1.0]. *)</langsyntaxhighlight>
 
=={{header|Oforth}}==
Line 1,559:
However, two identifiers ''can'' become “special”:
If you list in the <tt>program</tt> parameter list the identifiers of the spelling <tt>input</tt> and/or <tt>output</tt>, they will identify <tt>text</tt> variables referring to an implementation-defined input and output facility.
<langsyntaxhighlight lang="pascal">program foo(input, output);
begin
{ In this program, `input` and `output` have special meaning. }
end.</langsyntaxhighlight>
Neverthless, these identifiers are in no way ''reserved''.
<langsyntaxhighlight lang="pascal">program foo(output);
var
input: integer;
begin
{ In this program only `output` has special meaning. }
end.</langsyntaxhighlight>
Note that some run-time libraries of compilers usually ship a variety of predefined variables, but these are not part of the programming language itself.
 
Line 1,633:
 
=={{header|PL/I}}==
<syntaxhighlight lang="pl/i">
<lang PL/I>
Special variables in PL/I are termed "Pseudo-variables".
They are used only on the LHS of an assignment statement.
Line 1,655:
and may be used when a re-try of the conversion is to be
attempted with modified data).
</syntaxhighlight>
</lang>
 
=={{header|PowerShell}}==
This is the list:
<syntaxhighlight lang="powershell">
<lang PowerShell>
<#
$$
Line 1,700:
$True
#>
</syntaxhighlight>
</lang>
For descriptions:
<syntaxhighlight lang="powershell">
<lang PowerShell>
help about_automatic_variables
</syntaxhighlight>
</lang>
 
=={{header|PureBasic}}==
Line 1,711:
=={{header|Python}}==
By default, Python starts execution in a namespace which has direct access to names defined in the globals() dict and the __builtins__ dict. The members of which can be found by the following code:
<langsyntaxhighlight Pythonlang="python">names = sorted((set(globals().keys()) | set(__builtins__.__dict__.keys())) - set('_ names i'.split()))
print( '\n'.join(' '.join(names[i:i+8]) for i in range(0, len(names), 8)) )</langsyntaxhighlight>
;Output
<pre>ArithmeticError AssertionError AttributeError BaseException BufferError BytesWarning DeprecationWarning EOFError
Line 1,766:
 
Variables in Raku have a prefix sigil to distinguish them from named subroutines, functions, classes, and so on. There is a system of sigils to mark the fundamental structural type of the variable:
<syntaxhighlight lang="raku" perl6line> $foo scalar (object)
@foo ordered array
%foo unordered hash (associative array)
&foo code/rule/token/regex
::foo package/module/class/role/subset/enum/type/grammar</langsyntaxhighlight>
Sigils indicate overall interface, not the exact type of the bound object. Different sigils imply different minimal abilities. Ordinary sigils indicate normally scoped variables, either lexical or package scoped. Oddly scoped variables include a secondary sigil (a twigil) that indicates what kind of strange scoping the variable is subject to:
<syntaxhighlight lang="raku" perl6line> $foo # ordinary scoping
$.foo # object attribute public accessor
$^foo # self-declared formal positional parameter
Line 1,781:
$<foo> # match variable, short for $/{'foo'}
$!foo # object attribute private storage
$~foo # the foo sublanguage seen by the parser at this lexical spot</langsyntaxhighlight>
 
A selection (not comprehensive) of Raku's automatically set and/or pre-defined compile-time and run-time variables.
 
<syntaxhighlight lang="raku" perl6line># Lexical variables
 
$_ # implicit variable lexically scoped to the current block
Line 1,829:
$*COLLATION # object that can be used to configure Unicode collation levels
$*TOLERANCE # used by the =~= operator to decide if two values are approximately equal
$*DEFAULT-READ-ELEMS # affects the number of bytes read by default by IO::Handle.read</langsyntaxhighlight>
 
Also, not really a variable but...
<syntaxhighlight lang="raku" perl6line> * # A standalone term that has no fixed value, instead it captures the notion of "Whatever",
# the meaning of which is decided lazily by whatever it is an argument to.
# See the docs on Whatever: https://docs.raku.org/type/Whatever</langsyntaxhighlight>
 
=={{header|REXX}}==
Line 1,859:
In each case, the three special variable names &nbsp; ('''RC''', &nbsp; '''RESULT''', &nbsp; and &nbsp; '''SIGL''') &nbsp; may be in lower/upper/mixed case.
<br><br>The scope of the special variables is &nbsp; LOCAL.
<langsyntaxhighlight lang="rexx">/*REXX program demonstrates REXX special variables: RC, RESULT, SIGL */
/*line two. */
/*line three.*/ say copies('═',79)
Line 1,887:
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────HALVE subroutine────────────────────*/
halve: return arg(1) / 2 /*a simple halving function. */</langsyntaxhighlight>
'''output''' using:
:::* Regina REXX
Line 1,955:
Note that RETURN transfers control but does not set SIGL.
 
<langsyntaxhighlight lang="rexx">'dir a2.txt'
Say 'rc='rc
'dir 33.*'
Line 1,977:
Novalue:
Say 'NOVALUE encountered in line' sigl':' sourceline(sigl)
Exit </langsyntaxhighlight>
{{out}}
<pre> Datentr„ger in Laufwerk E: ist E_DESKTOP
Line 2,040:
* nil
Technically, these could be redefined, but the system would not work if any of them was. Therefore most compilers refuse code which obviously attempts to do so, and we can think of them as being reserved names as well.
Global binding names are returned by <syntaxhighlight lang ="smalltalk">Smalltalk keys</langsyntaxhighlight>
Things like the shell environment, command line argument, version numbers etc. are usually not exposed via globals, but instead held in private class variables (static variables), which can be accessed via getter messages (which, by the way, makes it easier to insert a dialect compatibility layer). An example for this would be: <langsyntaxhighlight lang="smalltalk">Float precision</langsyntaxhighlight> or <syntaxhighlight lang ="smalltalk">Smalltalk version</langsyntaxhighlight>
 
Name conventions:
Line 2,154:
 
=={{header|Ursa}}==
<langsyntaxhighlight lang="ursa"># contains arguments passed to the ursa
# interpreter on the command line
string<> args
Line 2,168:
 
# represents true
boolean true</langsyntaxhighlight>
 
=={{header|VBA}}==
Line 2,195:
=={{header|Wren}}==
Wren has two special variables ''this'' and ''super''. These can only be used in a constructor or instance method of a class. ''this'' refers to the current instance and ''super'' refers to a super-class whose constructor or (typically overridden) method you wish to invoke. Here's an example.
<langsyntaxhighlight lang="ecmascript">class Parent {
construct new(name) {
_name = name
Line 2,217:
 
var c = Child.new("John", "Fred")
c.printNames()</langsyntaxhighlight>
 
{{out}}
Line 2,242:
 
 
<langsyntaxhighlight lang="z80">org &0066
 
NMI_HANDLER: ;this label is optional, the CPU doesn't need it to know how to jump here.
retn ;in this example, the NMI routine will immediately return without doing anything.</langsyntaxhighlight>
 
The <code>I</code> register handles the interrupt operation in <code>IM 2</code> mode. The Game Boy does not have this register, as it handles interrupts differently.
 
The <code>r</code> register handles memory refresh. You should '''not''' write to this register, as doing so can damage your hardware. But reading from this register is safe. It basically contains a pseudo-random value, and while its randomness isn't sufficient to reliably seed a PRNG, it can be used to add a little "salt" to a random value. (It should be noted that the Game Boy doesn't have this register, so don't bother trying.)
<langsyntaxhighlight lang="z80"> ld a,r ;read from the refresh register.</langsyntaxhighlight>
 
=={{header|zkl}}==
<langsyntaxhighlight lang="zkl">__DATE__, __DEBUG__, __FILE__, __LINE__, __NAME__, __TIME__</langsyntaxhighlight>
As in the C preprocessor. Some (like __DEBUG__) can be changed, others (like __LINE__, __TIME__) are constants.
 
Line 2,331:
* 23732 P-RAMT - Address of last byte of physical RAM.
 
<langsyntaxhighlight lang="zxbasic">10 PRINT "The border colour is "; PEEK (23624): REM bordcr
20 PRINT "The ramtop address is "; PEEK (23730) + 256 * PEEK (23731): REM ramtop
30 POKE 23609,50: REM set keyboard pip to 50</langsyntaxhighlight>
 
{{omit from|GUISS|Does not have any variables at all}}
10,327

edits