- Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfeatures.html
185 lines (171 loc) · 6.76 KB
/
features.html
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<!DOCTYPE html>
<htmllang="en">
<head>
<metacharset="utf-8">
<metahttp-equiv="X-UA-Compatible" content="IE=edge">
<metaname="viewport" content="width=device-width, initial-scale=1">
<title>SmallBASIC | features</title>
<metaname="description" content="SmallBASIC | One more basic">
<linkrel="canonical" href="/features.html">
<linkrel="keywords" href="features">
<linkrel="stylesheet" href="/css/style.css">
<linkrel="icon" type="image/png" href="/images/sb-desktop-32x32.png">
<scriptsrc="/clipboard.js"></script>
</head>
<body>
<buttononclick="topFunction()" id="BackToTopBtn" title="Go to top">⯅</button>
<scriptsrc="/backtotop.js"></script>
<divclass="wrapAll clearfix">
<navclass="navigation">
<divclass="logo">
<ahref="/"><imgsrc='/images/sb-logo.png?v=2' alt="logo"></a>
</div>
<divclass="navlinks">
<ahref="/pages/download.html">Download</a>
<ahref="/pages/news.html">News</a>
<ahref="/pages/community.html">Community</a>
<aclass='active' href="/pages/articles.html">Resources</a>
<ahref="/pages/reference.html">Language Reference</a>
<ahref="/pages/guide.html">SmallBASIC Manual</a>
</div>
</nav>
<divclass="mainsection">
<divclass="tabs clearfix">
<divclass="tabsRight">
<atarget="_github" href="https://github.com/smallbasic/smallbasic.github.io/blob/master/_build/pages/features.markdown">Edit</a>
<atarget="_github" href="https://github.com/smallbasic/smallbasic.github.io/commits/master/_build/pages/features.markdown">History</a>
</div>
</div>
<divclass="article">
<h1id="new-features">New features</h1>
<blockquote>
<p>SmallBASIC has a number of new features intended to broaden its
appeal as a general purpose scripting language (Note - Written in
2008).</p>
</blockquote>
<h2id="local-variable-declaration-and-assignment">Local variable
declaration and assignment</h2>
<p>You can now declare and assign a local variable on the same line</p>
<pre><code>local foo = "foo"</code></pre>
<h2id="program-defined-window-geometry">Program defined window
geometry</h2>
<p>The SDL version now allow the window geometry to be set from your
program.</p>
<pre><code> option predef grmode 200x300</code></pre>
<h2id="user-defined-structures">User defined structures</h2>
<p>User defined structures in SmallBASIC are a form of compound variable
allowing individual elements to be referenced.</p>
<p>The following example loads the system password table and prints the
contents of the first user (works only in Linux):</p>
<pre><code>tload "/etc/passwd", buffer
dim users
for row in buffer
split row, ":", fields()
if (ubound(fields) > 0) then
local user
user.name = fields(0)
user.passwd = fields(1)
user.userId = fields(2)
user.groupId = fields(3)
users << user
fi
next row
print users(0)</code></pre>
<h2id="associative-arrays">Associative arrays</h2>
<p>Regular SmallBASIC arrays are indexed by integers within the upper
and lower bounds of the array. Associative arrays take a string as the
array index and like plain SmallBASIC variables, come into existence
when ever they are referenced.</p>
<p>The following example loads the system password table then prints the
groupID value of the “mail” user account:</p>
<pre><code>tload "/etc/passwd", buffer
users = {}
for row in buffer
split row, ":", fields()
if (ubound(fields) > 0) then
local user
user.name = fields(0)
user.passwd = fields(1)
user.userId = fields(2)
user.groupId = fields(3)
users(user.name) = user
fi
next row
print users("mail").userId</code></pre>
<h2id="unit-name-pathing">Unit name pathing</h2>
<p>Units now have the ability to include a path component in a unit
name.</p>
<pre><code>import other.something.foo
? foo.my_var</code></pre>
<p>Then in the foo.bas file:</p>
<pre><code>Unit other.something.Foo
export my_var</code></pre>
<p>The unit file would be saved in $UNITPATH/other/something. If not
defined, $UNITPATH is inferred from the host program directory.</p>
<h2id="in-operator">IN operator</h2>
<p>When applied to arrays the IN operator now returns the 1 based index
position, for example:</p>
<pre><code>a << "cat"
a << "dog"
print "dog" in a ' prints 2</code></pre>
<h2id="logical-expression-short-circuit-evaluation">Logical expression
short-circuit evaluation</h2>
<p>In the code fragment below, if A and B are both func’s and the A func
returns TRUE, then the B func is not called since the expression outcome
will still be the same, the expression will evaluate to TRUE.</p>
<pre><code>if (A OR B) ...</code></pre>
<p>In the next code fragment, if C and D are both func’s and the C func
returns FALSE, then the D func is not called since the expression
outcome will still be the same, the expression will evaluate to
FALSE.</p>
<pre><code>if (C AND D) ...</code></pre>
<h2id="funcsub-pointers">Func/Sub pointers</h2>
<p>The @ operator can be used to obtain the address of a sub or func.
The call statement is then used to invoke the sub or func pointed to by
the pointer variable.</p>
<pre><code>func foo(s)
foo="foo!"+s
end
sub bar
? "in bar"
end
p = @foo
? call(@foo, "#")
? call(p, "%")
pb = @bar
call pb
call @bar</code></pre>
<h2id="enhanced-chain">Enhanced chain</h2>
<p>The chain command can now take a string or array of strings as the
argument in lieu of a file name. After calling chain, the calling
program now successfully resumes.</p>
<pre><code>tload list, code
chain code</code></pre>
<h2id="lazy-strings">Lazy strings</h2>
<p>Strings are normally defined using double quote characters. If the
closing quote character is not present then the end of line marker is
used to terminate the string definition, for example:</p>
<pre><code>a = "this is a string
b = " and this is another string
? a;b</code></pre>
<h2id="double-equals">Double equals</h2>
<p>BASIC traditionally uses a single equals symbol for assignment and
comparison, for example:</p>
<pre><code>a = "cat"
if (a = "cat"): print "cat": endif</code></pre>
<p>SmallBASIC now allows you to use double equals to avoid a clash of
programming habits with other languages you may happen to use.</p>
<pre><code>a = "cat"
if (a == "cat"): print "cat": endif</code></pre>
</div>
<divclass="pagefooter">
This page was last edited on Fri, 28 Oct 2022 19:37:20 +0200
|
<ahref="https://en.wikipedia.org/wiki/Markdown" target="_blank" rel="nofollow">Markdown</a>
processed with
<ahref="https://pandoc.org/MANUAL.html#pandocs-markdown" target="_blank" rel="nofollow">pandoc 3.1.12.1</a>
</div>
</div>
</div>
</body>
</html>