Sprak syntax: Difference between revisions
From wikinotes
Line 23: | Line 23: | ||
= Datatypes = | = Datatypes = | ||
<blockquote> | |||
== Primitives == | |||
<blockquote> | <blockquote> | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
Line 31: | Line 33: | ||
number letterCount = Count(letters) # number of items in array | number letterCount = Count(letters) # number of items in array | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</blockquote><!-- Primitives --> | |||
== Strings == | |||
<blockquote> | |||
<syntaxhighlight lang="bash"> | |||
CharToInt("a") # (97) ascii value | |||
IntToChar(97) # ("a") ascii lookup | |||
# capitalize/uncapitalize by adding/subtracting 32 | |||
# iterate characters in string | |||
loop ch in mystring | |||
# ... | |||
end | |||
</syntaxhighlight> | |||
</blockquote><!-- Strings --> | |||
== Arrays == | |||
<blockquote> | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
Count(myarray) # size/length of array | Count(myarray) # size/length of array | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</blockquote><!-- Arrays --> | |||
</blockquote><!-- datatypes --> | </blockquote><!-- datatypes --> | ||
Revision as of 03:54, 9 January 2023
I/O
Print("something") # prints text 'something' Say("something") # prints, but out-loud (speech bubble?) var cmd = Input(">") # save user-input to variable
Variables
Assignment
var list = [false, true] # a list var myVar = 1.0 # ? automatically determine type?Scope
# looks like global variables are defined outside of function
Datatypes
Primitives
number myNum = 1234 string myStr = "test" bool myBol = false array letters = "abcdefg" # define an array number letterCount = Count(letters) # number of items in arrayStrings
CharToInt("a") # (97) ascii value IntToChar(97) # ("a") ascii lookup # capitalize/uncapitalize by adding/subtracting 32 # iterate characters in string loop ch in mystring # ... endArrays
Count(myarray) # size/length of array
Object Types
you can determine Item types with the
GetType()
command.GetType(myVar) # type introspectionfloppy # Floppy Diskette key # Keys
Loops
# Iterate over variable loop x from 1 to 8 Print( x ) end # Loop indefinitely (accepting commands) loop var cmd = Input(") ") end
Conditionals
if varA == varB # Unconfirmed Print("Success") else if varA == varC Print("Alternative Success") End()
Functions
# Define Function string MyFunction( string var ) return var End() void MyFunction( string var ) Print("no return value") End()# Test if function exists on platform if HasFunction("Print") Print("Success") End()
Misc
Random() # Random number Sleep(1) # Sleep time in seconds ClearCode() # (?) AppendCode() # (?)