Switching Files and Dictionaries Pre Release
Pre-release
Pre-release
Totobird-Creations
released this
23 Aug 23:05
·
76 commits
to master
since this release
Added:
- Switch statements
- Dictionaries
- Include statements
- Namespace type
- Attributes
- Lambdas
- Type built-in function
Modified:
- Less strict code block syntax
- Typed function arguments and return values
- Eqequals system for most types
Usage
# Switch statements
var fuel = 50
switch (var x as fuel) {
when (x < 0) {
print('Umm...')
}
when (x == 0) {
print('Out of fuel')
}
when (x <= 10) {
print('Almost out of fuel')
}
when (x <= 30) {
print('Might want to fill up')
}
when (x <= 60) {
print('Okay for now')
}
when (x <= 99) {
print('Almost full')
}
when (x == 100) {
print('Full')
}
else {
print('Too much')
}
}
# Dictionaries
var apples = {
'a': 'apple',
'b': 'babble',
'c': 'cobble',
'd': 'dabble',
'f': 'fable',
'g': 'gurgle',
'h': 'hurdle'
}
print(
apples['d']
)
# Include statements (Returns namespace type) & Attributes
var module = include('testmodule.peri')
print(str(
module.add(1, 2)
))
# Lambdas
var add = lambda(a: int, b: int) -> int {a + b}
print(str(
add(1, 2)
))
# Type built-in function
var string = type('hello')
print(str(
string
))
print(
string(10.0)
)
# Code block syntax is less strict
func (a: int, b: int) -> int {i_can_put_stuff_here('hello')
and_here('hello')}
# Function arguments and return values are typed
func(a: int, b: int) -> float {
# ^^^ ^^^ ^^^^^
return(float(a + b))
}