Saffron

A general-purpose programming language with dynamic typing.

Standard Library

Saffron comes with a standard library of functions that provide support for console I/O, string manipulation and data conversion.

Console

writeln

Write the given value to the console, followed by a new-line character at the end.

writeln(value)

write

Write the given value to the console (no new-line character at the end).

write(value)

readln

Read a line of text from the console. Returns when the user presses ENTER.

readln()

Strings

str_length

Get the length of the source string.

str_length(source)

str_substr

Get a sub-string of the source string.

The sub-string will be from the start position till the end position, inclusive.

Positions are zero-based i.e., the position of the first character is 0 and the position of the last character is length - 1.

Throws INDEX_OUT_OF_BOUNDS_EXCEPTION if the value of start or end is outside the range [0 to length-1].

str_substr(source, start, end)

str_replace

Replace all occurrences of search with replace, in source.

This function does not modify the original string, but returns a new one.

str_replace(source, search, replace)

str_trim

Trim whitespace from the beginning and end of the source string.

This function does not modify the original string, but returns a new one.

str_trim(source)

str_contains

Find whether the source string contains the search string.

str_contains(source, search)

str_startswith

Find whether the source string starts with the search string.

str_startswith(source, search)

str_endswith

Find whether the source string ends with the search string.

str_endswith(source, search)

Data Conversion

to_num

Parse the source string as a number.

Throws FORMAT_EXCEPTION if source is not in a valid number format.

to_num(source)

to_bool

Parse the source string as a boolean.

Throws FORMAT_EXCEPTION if source is not a valid boolean value.

to_bool(source)

to_str

Convert the source value to its string representation. The source value can be a number, boolean or string

to_str(source)