rsc3/doc-schelp/Help-3.12.2/Classes/Interpreter.html

178 lines
No EOL
17 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<html><head><title>Interpreter</title>
<link rel='stylesheet' href='./../scdoc.css' type='text/css' />
<link rel='stylesheet' href='./../frontend.css' type='text/css' />
<link rel='stylesheet' href='./../custom.css' type='text/css' />
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
<script src='./../scdoc.js' type='text/javascript'></script>
<script src='./../docmap.js' type='text/javascript'></script>
<script src='./../prettify.js' type='text/javascript'></script>
<script src='./../lang-sc.js' type='text/javascript'></script>
<script type='text/javascript'>var helpRoot='./..';</script>
</head>
<ul id='menubar'></ul>
<body onload='fixTOC();prettyPrint()'>
<div class='contents'>
<div class='header'>
<div id='label'>SuperCollider CLASSES</div>
<div id='categories'><a href='./../Browse.html#Core>Kernel'>Core>Kernel</a></div>
<h1>Interpreter</h1>
<div id='summary'>The interpreter defines a context in which interactive commands are compiled and executed.</div>
</div>
<div class='subheader'>
<div id='filename'>Source: <a href='file:///Applications/SuperCollider.app/Contents/Resources/SCClassLibrary/Common/Core/Kernel.sc'>/Applications/SuperCollider.app/Contents/Resources/SCClassLibrary/Common/Core/Kernel.sc</a></div><div id='superclasses'>Inherits from: <a href="../Classes/Object.html">Object</a></div>
<div id='related'>See also: <a href="./../How-to-Use-the-Interpreter">How-to-Use-the-Interpreter</a></div>
</div>
<div id='toc'>
<ul class='toc'><li class='toc1'><a href='#description'>Description</a></li>
<ul class='toc'></ul><li class='toc1'><a href='#classmethods'>Class methods</a></li>
<ul class='toc'><li class='toc2'><a href='#Inherited%20class%20methods'>Inherited class methods</a></li>
</ul><li class='toc1'><a href='#instancemethods'>Instance methods</a></li>
<ul class='toc'><li class='toc2'><a href='#Accessing'>Accessing</a></li>
<ul class='toc'><li class='toc3'><a href='#-clearAll'>clearAll</a> </li>
</ul><li class='toc2'><a href='#Compile%20&%20Interpret'>Compile &amp; Interpret</a></li>
<ul class='toc'><li class='toc3'><a href='#-interpret'>interpret</a> </li>
<li class='toc3'><a href='#-interpretPrint'>interpretPrint</a> </li>
<li class='toc3'><a href='#-compile'>compile</a> </li>
<li class='toc3'><a href='#-compileFile'>compileFile</a> </li>
<li class='toc3'><a href='#-executeFile'>executeFile</a> </li>
<li class='toc3'><a href='#-cmdLine'>cmdLine</a> </li>
<li class='toc3'><a href='#-codeDump'>codeDump</a> </li>
<li class='toc3'><a href='#-preProcessor'>preProcessor</a> </li>
<li class='toc3'><a href='#-a'>a</a> <a href='#-b'>b</a> <a href='#-c'>c</a> <a href='#-d'>d</a> <a href='#-e'>e</a> <a href='#-f'>f</a> <a href='#-g'>g</a> <a href='#-h'>h</a> <a href='#-i'>i</a> <a href='#-j'>j</a> <a href='#-k'>k</a> <a href='#-l'>l</a> <a href='#-m'>m</a> <a href='#-n'>n</a> <a href='#-o'>o</a> <a href='#-p'>p</a> <a href='#-q'>q</a> <a href='#-r'>r</a> <a href='#-s'>s</a> <a href='#-t'>t</a> <a href='#-u'>u</a> <a href='#-v'>v</a> <a href='#-w'>w</a> <a href='#-x'>x</a> <a href='#-y'>y</a> <a href='#-z'>z</a> </li>
</ul><li class='toc2'><a href='#Inherited%20instance%20methods'>Inherited instance methods</a></li>
<li class='toc2'><a href='#Undocumented%20instance%20methods'>Undocumented instance methods</a></li>
<ul class='toc'><li class='toc3'><a href='#-functionCompileContext'>functionCompileContext</a> </li>
<li class='toc3'><a href='#-interpretCmdLine'>interpretCmdLine</a> </li>
<li class='toc3'><a href='#-interpretPrintCmdLine'>interpretPrintCmdLine</a> </li>
<li class='toc3'><a href='#-shallowCopy'>shallowCopy</a> </li>
</ul></ul></ul></div><h2><a class='anchor' name='description'>Description</a></h2>
<p>The interpreter is an object that handles the translation and execution of code at runtime. It is that what runs any program code and defines a context for it.<pre class='code prettyprint lang-sc'>(
a = 5 + 7;
this.cmdLine.postln;
)</pre>
<h2><a class='anchor' name='classmethods'>Class Methods</a></h2>
<h3><a class='anchor' name='Inherited%20class%20methods'>Inherited class methods</a></h3>
<div id='inheritedclassmets'></div><h2><a class='anchor' name='instancemethods'>Instance Methods</a></h2>
<h3><a class='anchor' name='Accessing'>Accessing</a></h3>
<p>In the interpreter, <code class='code prettyprint lang-sc'>this</code> refers to the interpreter itself, e.g.: <code class='code prettyprint lang-sc'>this.postln</code>
<p>The interpreter defines global variables (<code class='code prettyprint lang-sc'>a</code><code class='code prettyprint lang-sc'>z</code>), that can be used for interactive programming. Except these single letter variables ("interpreter variables"), all variables have to be defined by the keyword <code class='code prettyprint lang-sc'>var</code> (see: <a href="./../Reference/Assignment.html">Assignment Statements</a>, and <a href="./../Reference/Scope.html">Scoping and Closure</a>).<pre class='code prettyprint lang-sc'>// typical usage
a = 4;
b = 3;
b = b + a;
// some sound
a = Synth(\default);
g = fork { loop { 0.1.wait; a.set(\freq, 200 + 20.0.rand2.postln) } };
g.stop; a.free;
// an overview of all the variables
this.inspect;</pre>
<div class='note'><span class='notelabel'>NOTE:</span> Use these variables with a bit of extra care as they are global, they remain in memory and one piece of code may happen to interfere with another one. The variable <code class='code prettyprint lang-sc'>s</code> is by convention bound to the default server (<a href="./../Classes/Server.html">Server</a>) and should not be changed.</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-clearAll' href='./../Overviews/Methods.html#clearAll'>clearAll</a> </h3>
<div class='method'>
<p>set the values of the variables <code class='code prettyprint lang-sc'>a</code> through <code class='code prettyprint lang-sc'>z</code> to nil.<pre class='code prettyprint lang-sc'>x = 123;
x.postln;
this.clearAll;
x.postln;</pre>
</div><h3><a class='anchor' name='Compile%20&%20Interpret'>Compile &amp; Interpret</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-interpret' href='./../Overviews/Methods.html#interpret'>interpret</a> (<span class='argstr'>string</span> <span class='argstr'>... args</span>)</h3>
<div class='method'>
<p>Compile and execute a <a href="./../Classes/String.html">String</a>.<pre class='code prettyprint lang-sc'>this.interpret("(123 + 4000).postln");</pre>
</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-interpretPrint' href='./../Overviews/Methods.html#interpretPrint'>interpretPrint</a> (<span class='argstr'>string</span> <span class='argstr'>... args</span>)</h3>
<div class='method'>
<p>Compile and execute a <a href="./../Classes/String.html">String</a>, printing the result.<pre class='code prettyprint lang-sc'>this.interpretPrint("123 + 4000");</pre>
</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-compile' href='./../Overviews/Methods.html#compile'>compile</a> (<span class='argstr'>string</span>)</h3>
<div class='method'>
<p>Compile a String and return a <a href="./../Classes/Function.html">Function</a>.<pre class='code prettyprint lang-sc'>(
z = this.compile("(123 + 4000).postln");
z.postln;
z.value;
)</pre>
</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-compileFile' href='./../Overviews/Methods.html#compileFile'>compileFile</a> (<span class='argstr'>pathName</span>)</h3>
<div class='method'>
<p>Reads the file at pathName, compiles it and returns a Function. The file must contain a valid SuperCollider expression, naturally. This will not compile class definitions, only expressions.</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-executeFile' href='./../Overviews/Methods.html#executeFile'>executeFile</a> (<span class='argstr'>pathName</span> <span class='argstr'>... args</span>)</h3>
<div class='method'>
<p>Reads the file at pathName, compiles it and executes it, returning the result. The file must contain a valid SuperCollider expression, naturally. This will not compile class definitions, only expressions.</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-cmdLine' href='./../Overviews/Methods.html#cmdLine'>cmdLine</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-cmdLine' href='./../Overviews/Methods.html#cmdLine'>cmdLine</a> = value</h3>
<div class='method'>
<p>Returns the previously interpreted code.<pre class='code prettyprint lang-sc'>1 + 2;
this.cmdLine</pre>
</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-codeDump' href='./../Overviews/Methods.html#codeDump'>codeDump</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-codeDump' href='./../Overviews/Methods.html#codeDump'>codeDump</a> = value</h3>
<div class='method'>
<p>this interpreter variable can be set to evaluate a function with any successfully compiled code. see e.g. the class History.<pre class='code prettyprint lang-sc'>a = [ ]; // store all the code evaluated in a
this.codeDump = { |code| a = a.add(code) };
1 + 3;
f = { "hallo" };
a.postcs;
codeDump = nil; // reset to nil.</pre>
</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-preProcessor' href='./../Overviews/Methods.html#preProcessor'>preProcessor</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-preProcessor' href='./../Overviews/Methods.html#preProcessor'>preProcessor</a> = value</h3>
<div class='method'>
<p>can be used to modify code before it is interpreted. Given appropriate delimiters, this can be used to implement little languages.<pre class='code prettyprint lang-sc'>// silly but simple: understand a Saw for every SinOsc
this.preProcessor = { |code| code.replace("SinOsc", "Saw") };
{ SinOsc.ar(200) * 0.1 }.play;
preProcessor = nil; // reset to nil.</pre>
</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-a' href='./../Overviews/Methods.html#a'>a</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-a' href='./../Overviews/Methods.html#a'>a</a> = value</h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-b' href='./../Overviews/Methods.html#b'>b</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-b' href='./../Overviews/Methods.html#b'>b</a> = value</h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-c' href='./../Overviews/Methods.html#c'>c</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-c' href='./../Overviews/Methods.html#c'>c</a> = value</h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-d' href='./../Overviews/Methods.html#d'>d</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-d' href='./../Overviews/Methods.html#d'>d</a> = value</h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-e' href='./../Overviews/Methods.html#e'>e</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-e' href='./../Overviews/Methods.html#e'>e</a> = value</h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-f' href='./../Overviews/Methods.html#f'>f</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-f' href='./../Overviews/Methods.html#f'>f</a> = value</h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-g' href='./../Overviews/Methods.html#g'>g</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-g' href='./../Overviews/Methods.html#g'>g</a> = value</h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-h' href='./../Overviews/Methods.html#h'>h</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-h' href='./../Overviews/Methods.html#h'>h</a> = value</h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-i' href='./../Overviews/Methods.html#i'>i</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-i' href='./../Overviews/Methods.html#i'>i</a> = value</h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-j' href='./../Overviews/Methods.html#j'>j</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-j' href='./../Overviews/Methods.html#j'>j</a> = value</h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-k' href='./../Overviews/Methods.html#k'>k</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-k' href='./../Overviews/Methods.html#k'>k</a> = value</h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-l' href='./../Overviews/Methods.html#l'>l</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-l' href='./../Overviews/Methods.html#l'>l</a> = value</h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-m' href='./../Overviews/Methods.html#m'>m</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-m' href='./../Overviews/Methods.html#m'>m</a> = value</h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-n' href='./../Overviews/Methods.html#n'>n</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-n' href='./../Overviews/Methods.html#n'>n</a> = value</h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-o' href='./../Overviews/Methods.html#o'>o</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-o' href='./../Overviews/Methods.html#o'>o</a> = value</h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-p' href='./../Overviews/Methods.html#p'>p</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-p' href='./../Overviews/Methods.html#p'>p</a> = value</h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-q' href='./../Overviews/Methods.html#q'>q</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-q' href='./../Overviews/Methods.html#q'>q</a> = value</h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-r' href='./../Overviews/Methods.html#r'>r</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-r' href='./../Overviews/Methods.html#r'>r</a> = value</h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-s' href='./../Overviews/Methods.html#s'>s</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-s' href='./../Overviews/Methods.html#s'>s</a> = value</h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-t' href='./../Overviews/Methods.html#t'>t</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-t' href='./../Overviews/Methods.html#t'>t</a> = value</h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-u' href='./../Overviews/Methods.html#u'>u</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-u' href='./../Overviews/Methods.html#u'>u</a> = value</h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-v' href='./../Overviews/Methods.html#v'>v</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-v' href='./../Overviews/Methods.html#v'>v</a> = value</h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-w' href='./../Overviews/Methods.html#w'>w</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-w' href='./../Overviews/Methods.html#w'>w</a> = value</h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-x' href='./../Overviews/Methods.html#x'>x</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-x' href='./../Overviews/Methods.html#x'>x</a> = value</h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-y' href='./../Overviews/Methods.html#y'>y</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-y' href='./../Overviews/Methods.html#y'>y</a> = value</h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-z' href='./../Overviews/Methods.html#z'>z</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-z' href='./../Overviews/Methods.html#z'>z</a> = value</h3>
<div class='method'>
<p>Global variables ("interpreter variables") for interactive programming (see <a href="#Accessing">Accessing</a>).</div><h3><a class='anchor' name='Inherited%20instance%20methods'>Inherited instance methods</a></h3>
<div id='inheritedinstmets'></div><h3><a class='anchor' name='Undocumented%20instance%20methods'>Undocumented instance methods</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-functionCompileContext' href='./../Overviews/Methods.html#functionCompileContext'>functionCompileContext</a> </h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-interpretCmdLine' href='./../Overviews/Methods.html#interpretCmdLine'>interpretCmdLine</a> </h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-interpretPrintCmdLine' href='./../Overviews/Methods.html#interpretPrintCmdLine'>interpretPrintCmdLine</a> </h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-shallowCopy' href='./../Overviews/Methods.html#shallowCopy'>shallowCopy</a> </h3>
<div class='doclink'>helpfile source: <a href='file:///Applications/SuperCollider.app/Contents/Resources/HelpSource/Classes/Interpreter.schelp'>/Applications/SuperCollider.app/Contents/Resources/HelpSource/Classes/Interpreter.schelp</a><br>link::Classes/Interpreter::<br>sc version: 3.8.0</div></div></body></html>