Home › Built-ins
Collections, strings, numbers, dates, math, encoding, crypto, and file operations.
local(a) = array(1, 2, 3)
#a->size // 3
#a->last // 3
#a->at(2) // 2
#a->insert(4) // append
#a->append(5)
#a->prepend(0)
#a->set(1, 99) // set index 1 to 99
#a->remove(2) // remove at index 2
#a->pop // remove and return last
#a->shift // remove and return first
#a->sort
#a->reverse
#a->join(', ') // 'a, b, c'
#a->sum
#a->average
#a->min
#a->max
#a->removeAll
#a->merge(array(6, 7))
local(sa) = staticarray(10, 20, 30) #sa->size #sa->at(1)
local(m) = map(-name='Ada', -year=1843)
#m->get('name') // 'Ada'
#m->find('year') // 1843
#m->containsKey('role') // false
#m->keys // array of key names
#m->values // array of values
#m->insert('role', 'mathematician')
#m->set('year', 1815)
#m->remove('role')
#m->merge(map(-active=true))
#m->removeAll
local(p) = pair('hello', 42)
#p->first // 'hello'
#p->second // 42
'Ada'->uppercase // 'ADA'
'ADA'->lowercase // 'ada'
'ada lovelace'->capitalize // 'Ada lovelace'
'Ada'->reverse // 'adA'
' Ada '->trim // 'Ada'
'Ada Lovelace'->split(' ') // array('Ada', 'Lovelace')
'Lasso'->replace('ss', 'ir') // 'Lairo'
'prefix-value'->removeLeading('prefix-') // 'value'
'file.lasso'->removeTrailing('.lasso') // 'file'
'abcabc'->findPosition('ca') // 3
'LaiRu'->byteLength // byte count
'LaiRu'->bytes // array of byte values
array(76, 97, 105)->decodeBytes // 'Lai'
'ha'->repeat(3) // 'hahaha'
'7'->padLeading(3, '0') // '007'
'x'->padTrailing(4, '.') // 'x...'
'LaiRu'->substring(2, 3) // 'aiR'
'LaiRu'->left(3) // 'Lai'
'LaiRu'->right(2) // 'Ru'
'LaiRu'->beginsWith('Lai') // true
'LaiRu'->endsWith('Ru') // true
'LaiRu'->indexOf('Ru') // 4
'Hello World'->forEachWord => {^ #1 ^}
'abc'->forEachCharacter => {^ #1 ^}
integer('42') // 42
decimal('3.14') // 3.14
boolean(0) // false
string(42) // '42'
42->asString // '42'
'42'->asInteger // 42
'3.14'->asDecimal // 3.14
42->asBoolean // true
Integer arithmetic is arbitrary-precision. There is no integer overflow.
math_abs(-5) // 5 math_pow(2, 10) // 1024 math_sqrt(16) // 4.0 math_floor(3.7) // 3 math_ceiling(3.2) // 4 math_round(3.5) // 4
local(now) = date()
#now->format('YYYY-MM-dd HH:mm:ss')
#now->formatUTC('YYYY-MM-dd')
#now->hour
#now->minute
#now->second
#now->weekday
#now->dayOfMonth
#now->monthName
#now->monthAbbrev
#now->weekdayName
#now->timezone
#now->add(3600) // add seconds
#now->subtract(60) // subtract seconds
date_utc() // current UTC date
date_gmt() // alias for date_utc
date_now() // alias for date()
date_timezone() // server timezone string
date_parse('2025-01-01')
date_format(#now, 'YYYY-MM-dd')
date_add(#now, 86400)
date_subtract(#now, 3600)
encode_html('<b>bold</b>') // '<b>bold</b>'
html_encode(...) // alias
escape_html(...) // alias
encode_url('hello world') // 'hello+world'
url_encode(...) // alias
'<p>'->encodeHtml
'hello world'->encodeUrl
json_encode(array(1, 2, 3)) // '[1,2,3]'
json_encode(map(-name='Ada')) // '{"name":"Ada"}'
json_decode('[1, 2, 3]') // array(1, 2, 3)
json_decode('{"active":true}') // map(-active=true)
JSON encode supports null, booleans, integers, finite decimals, strings, arrays, maps, and acyclic custom objects (as visible-field maps). It fails for captures, dates, non-finite decimals, and cyclic object graphs.
digest_md5('hello') // hex MD5 digest
md5('hello') // alias
digest_sha1('hello') // hex SHA-1 digest
sha1('hello') // alias
random_bytes(16) // 16 random bytes as array
random_hex(8) // 16-char hex string (8 bytes)
uuid // random UUID v4 string
uuid_v4 // alias
random_uuid // alias
File APIs honour LAIRU_FILE_ROOT when set. Relative paths are resolved under
that root and parent-directory escapes are rejected. Set
LAIRU_FILE_ROOT_REQUIRED=1 to disallow file access without a configured root.
file_exists('/path/to/file')
file_read('/path/to/file')
file_write('/path/to/file', 'content')
file_append('/path/to/file', 'more')
file_create('/path/to/newfile')
file_delete('/path/to/file')
file_copy('/src', '/dst')
file_move('/src', '/dst')
file_size('/path/to/file')
file_mtime('/path/to/file')
file_info('/path/to/file') // map of metadata
file_is_file('/path')
file_is_directory('/path')
file_is_readable('/path')
file_is_writable('/path')
file_basename('/var/www/index.lasso') // 'index.lasso'
file_extension('/var/www/index.lasso') // '.lasso'
file_dirname('/var/www/index.lasso') // '/var/www'
file_permissions('/path')
file_chmod('/path', 0o644)
file_list('/var/www/html')
directory_exists('/path')
directory_create('/path')
directory_delete('/path')
directory_list('/path')
path_normalize('/var/../var/www')
path_clean('/var/../var/www')
path_basename('/var/www/index.lasso')
path_parent('/var/www/index.lasso')
fail('message')
fail(-type='security', -code=403, 'denied')
protect => {
handle_failure => { error_msg }
fail('boom')
}
rethrow // inside a handler: re-raise
error_current // active error object
error_msg // message string
error_type // type tag, if set
error_code // numeric code, if set
error_line // source line (when available)
error_column // source column
error_stack // stack trace string
size(value) // length of string, array, map, etc.
byte_length(value) // byte length of string
bytes_encode(value)
bytes_decode(array(65, 66)) // 'AB'
sleep(500) // sleep 500 ms
sleep_milliseconds(500)
type_name(value) // type name of any value
type_is(value, 'string') // true / false
value->type // member form
value->isA('string') // member form