Category talk:EasyLang
Appearance
Here are some common code snippets for implementing tasks in EasyLang.
Associative arrays
The syntax for an associative arrays in EasyLang should look like this:
associative$[][] = [ [ 3 "associative" ] [ 7 "arrays" ] ]
Indexing associative arrays
For associative number arrays:
proc indexAssoc index . array[][] item .
for i = 1 to len array[][]
if array[i][1] = index
item = array[i][2]
return
.
.
item = number "nan"
.
For associative string arrays:
proc indexStrAssoc index$ . array$[][] item$ .
for i = 1 to len array$[][]
if array$[i][1] = index$
item$ = array$[i][2]
return
.
.
item$ = ""
.
Case conversion
These functions only work with ASCII characters.
Lowercase
func$ toLowercase string$ .
for i = 1 to len string$
code = strcode substr string$ i 1
if code >= 65 and code <= 90
code += 32
.
result$ &= strchar code
.
return result$
.
Uppercase
func$ toUppercase string$ .
for i = 1 to len string$
code = strcode substr string$ i 1
if code >= 97 and code <= 122
code -= 32
.
result$ &= strchar code
.
return result$
.
Find in array
This function is for number arrays:
func findInArray array[] item .
for i = 1 to len array[]
if array[i] = item
return i
.
.
return 0
.
This function is for string arrays:
func findInStrArray array$[] item$ .
for i = 1 to len array$[]
if array$[i] = item$
return i
.
.
return 0
.
Sum and product of arrays
func sum array[] .
for item in array[]
result += item
.
return result
.
func product array[] .
result = 1
for item in array[]
result *= item
.
return result
.