Runtime Types
- Int: signed 64bit integer
- BigInt: arbitrary-precision integer (big integer)
- String: string
- Float: 64bit floating point
- BigFloat: arbitrary-precision floating point (big float)
- Complex: complex numbers (
complex128in go) - Bool: boolean
- Char: character (
runein Go) - Bytes: byte array (
[]bytein Go) - Array: objects array (
[]Objectin Go) - ImmutableArray: immutable object array (
[]Objectin Go) - Map: objects map with string keys (
map[string]Objectin Go) - ImmutableMap: immutable object map with string keys (
map[string]Objectin Go) - Time: time (
time.Timein Go) - Error: an error with underlying Object value of any type
- Null: null
Type Conversion/Coercion Table
| src\dst | Int | String | Float | Bool | Char | Bytes | Array | Map | Time | Error | Null |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Int | - | strconv | float64(v) | !IsFalsy() | rune(v) | X | X | X | time.Unix() | X | X |
| BigInt | - | - | !IsFalsy() | - | X | X | X | - | X | X | |
| String | strconv | - | strconv | !IsFalsy() | X | []byte(s) | X | X | X | X | X |
| Float | int64(f) | strconv | - | !IsFalsy() | X | X | X | X | X | X | X |
| BigFloat | - | - | !IsFalsy() | - | X | X | X | - | X | X | |
| Bool | 1 / 0 | "true" / "false" | X | - | X | X | X | X | X | X | X |
| Char | int64(c) | string(c) | X | !IsFalsy() | - | X | X | X | X | X | X |
| Bytes | X | string(y) | X | !IsFalsy() | X | - | X | X | X | X | X |
| Array | X | "[...]" | X | !IsFalsy() | X | X | - | X | X | X | X |
| Map | X | "{...}" | X | !IsFalsy() | X | X | X | - | X | X | X |
| Time | X | String() | X | !IsFalsy() | X | X | X | X | - | X | X |
| Error | X | "error: ..." | X | false | X | X | X | X | X | - | X |
| Null | X | X | X | false | X | X | X | X | X | X | - |
X: No conversion; Typed value functions for Variable will
return zero values.
strconv: converted using Go's conversion functions from strconv package.
IsFalsy(): use Object.IsFalsy() function_
_ String(): use Object.String() function
* time.Unix(): use time.Unix(v, 0) to convert to Time
Object.IsFalsy()
Object.IsFalsy() interface method is used to determine if a given value
should evaluate to false (e.g. for condition expression of if statement).
- Int:
n == 0 - String:
len(s) == 0 - Float:
isNaN(f) - Bool:
!b - Char:
c == 0 - Bytes:
len(bytes) == 0 - Array:
len(arr) == 0 - Map:
len(map) == 0 - Time:
Time.IsZero() - Error:
true(Error is always falsy) - Null:
true(Null is always falsy)
Type Conversion Builtin Functions
string(x): tries to convertxinto string; returnsnullif failedint(x): tries to convertxinto int; returnsnullif failedbool(x): tries to convertxinto bool; returnsnullif failedfloat(x): tries to convertxinto float; returnsnullif failedchar(x): tries to convertxinto char; returnsnullif failedbytes(x): tries to convertxinto bytes; returnsnullif failedbytes(N): as a special case this will create a Bytes variable with the given sizeN(only ifNis int)time(x): tries to convertxinto time; returnsnullif failed
Type Checking Builtin Functions
is_string(x): returnstrueifxis string;falseotherwiseis_int(x): returnstrueifxis int;falseotherwiseis_bigint(x): returnstrueifxis bigint;falseotherwiseis_bool(x): returnstrueifxis bool;falseotherwiseis_float(x): returnstrueifxis float;falseotherwiseis_bigfloat(x): returnstrueifxis bigfloat;falseotherwiseis_complex(x): returnstrueifxis complex;falseotherwiseis_char(x): returnstrueifxis char;falseotherwiseis_bytes(x): returnstrueifxis bytes;falseotherwiseis_array(x): returntrueifxis array;falseotherwiseis_immutable_array(x): returntrueifxis immutable array;falseotherwiseis_map(x): returntrueifxis map;falseotherwiseis_immutable_map(x): returntrueifxis immutable map;falseotherwiseis_time(x): returntrueifxis time;falseotherwiseis_error(x): returnstrueifxis error;falseotherwiseis_null(x): returnstrueifxis null;falseotherwise