forked from verhas/jScriptBasic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsub.html
More file actions
148 lines (109 loc) · 8.44 KB
/
Copy pathsub.html
File metadata and controls
148 lines (109 loc) · 8.44 KB
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
| Generated by Apache Maven Doxia at Jan 17, 2013
| Rendered using Apache Maven Fluido Skin 1.2.1
-->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>jScriptBasic - jScriptBasic Project Documentation</title>
<link rel="stylesheet" href="../css/apache-maven-fluido.min.css" />
<link rel="stylesheet" href="../css/site.css" />
<link rel="stylesheet" href="../css/print.css" media="print" />
<script type="text/javascript" src="../js/apache-maven-fluido.min.js"></script>
<meta name="author" content="Peter Verhas" />
<meta name="Date-Creation-yyyymmdd" content="20120814" />
<meta name="Date-Revision-yyyymmdd" content="20130117" />
<meta http-equiv="Content-Language" content="en" />
</head>
<body class="topBarDisabled">
<div class="container-fluid">
<div id="banner">
<div class="pull-left">
<a href="http://scriptbasic.com" id="bannerLeft">
<img src="../" alt="ScriptBasic for Java"/>
</a>
</div>
<div class="pull-right"> </div>
<div class="clear"><hr/></div>
</div>
<div id="breadcrumbs">
<ul class="breadcrumb">
<li id="publishDate">Last Published: 2013-01-17</li>
<li class="divider">|</li> <li id="projectVersion">Version: 1.0.4-SNAPSHOT</li>
<li class="pull-right"> <a href="http://scriptbasic.com" class="externalLink" title="ScriptBasic">ScriptBasic</a>
</li>
</ul>
</div>
<div class="row-fluid">
<div id="leftColumn" class="span3">
<div class="well sidebar-nav">
<h3>Documentation for SB4J</h3>
<ul>
<li class="none">
<a href="../intro.html" title="Introduction">Introduction</a>
</li>
<li class="none">
<a href="../name.html" title="Name of the game">Name of the game</a>
</li>
<li class="none">
<a href="../design.html" title="History and Design Goals">History and Design Goals</a>
</li>
<li class="none">
<a href="../basic.html" title="Basic Language Implemented">Basic Language Implemented</a>
</li>
<li class="none">
<a href="../install.html" title="Installation">Installation</a>
</li>
<li class="none">
<a href="../advanced/index.html" title="Embedding API">Embedding API</a>
</li>
<li class="none">
<a href="../configure.html" title="Configuration">Configuration</a>
</li>
</ul>
<h3>Project Documentation</h3>
<ul>
<li class="collapsed">
<a href="../project-info.html" title="Project Information">Project Information</a>
</li>
<li class="collapsed">
<a href="../project-reports.html" title="Project Reports">Project Reports</a>
</li>
</ul>
<hr class="divider" />
<div id="poweredBy">
<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
<div class="g-plusone" data-href="http://www.scriptbasic.com" data-size="tall" ></div>
<div class="clear"></div>
<div class="clear"></div>
<div class="clear"></div>
<a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy">
<img class="poweredBy" alt="Built by Maven" src="../images/logos/maven-feather.png" />
</a>
</div>
</div>
</div>
<div id="bodyColumn" class="span9" >
<div class="section"><h2>Subroutines<a name="Subroutines"></a></h2><p>Subroutines are first class citizens in ScriptBasic for Java. You can write subroutines in your BASIC program and call them from the main part of the BASIC program, or from another subroutine or from the same subroutine recursively.</p><p>ScriptBasic for Java subroutines can have return values. There is no syntactic difference between subroutines and functions, procedures or anything else. There is subroutine only, that may return some value at its will. To return a value the statement <tt>RETURN</tt> is to be used. The format of a subroutine is:</p><div><pre>SUB mySubroutine [ ( arguments ) ]
commands
[ RETURN expression ]
ENDSUB</pre></div><p>A subroutine starts with the keyword <tt>SUB</tt> and should have a unique name. You can not have two subroutines having the same name in a BASIC program. A subroutine can have arguments, but they are optional. If the subroutine does not have arguments, then you can optionally leave the parentheses off and you can simply write</p><div><pre>SUB mySubroutine
commands
ENDSUB</pre></div><p>or you can write, just as well</p><div><pre>SUB mySubroutine()
commands
ENDSUB</pre></div><p>Both approaches are equally good. However when you use a subroutine in an expression you can not omit the opening and closing parentheses. If you do so, the interpreter will treat the identifier as an undeclared variable and will not call the subroutine. Instead you will probably get <tt>undef</tt> value. It is generally bad practice to use the same identifier to name a subroutine and a variable, but ScriptBasic for Java does not prevent you.</p><p>If you have arguments they behave like local variables. If there are arguments for your subroutine you have to provide those values when you call the subroutine. You have to provide exactly that many arguments as many the subroutine expects otherwise you will receive runtime error. (Note that later versions will check this during compile time.)</p><p>To invoke a subroutine you can use the name of the subroutine in an expression followed by <tt>(</tt> and <tt>)</tt> and an expression list between the parentheses, like</p><div><pre>a = 1 + mySubroutine(13,"apple","pie")</pre></div><p>If your subroutine does not return any value then the special value <tt>undef</tt> will be used as return value. If your subroutine is more a real subroutine than a function call you can call it using the keyword <tt>CALL</tt>:</p><div><pre>CALL mySubroutine(13,"apple","pie")</pre></div><p>ScriptBasic for Java is quite liberal with the keyword <tt>CALL</tt> making it optional. Thus you can also write</p><div><pre>mySubroutine(13,"apple","pie")</pre></div><p>You can also omit the opening and closing parentheses, thus it becomes:</p><div><pre>CALL mySubroutine 13,"apple","pie"</pre></div><p>or</p><div><pre>mySubroutine 13,"apple","pie"</pre></div><p>with this features ScriptBasic for Java can be used as a simple domain specific language implementation. </p></div>
</div>
</div>
<hr/>
<footer>
<div class="container-fluid">
<div class="row span16">Copyright © 2013
<a href="http://www.verhas.com">Verhas and Verhas Software Craftsmen</a>.
All Rights Reserved.
</div>
</div>
</footer>
</body>
</html>