Type Conversion
Inspect values with nooc() and convert between integers, floating-point numbers, strings, and booleans.
Type Conversion in Soplang
Soplang provides built-in functions for inspecting types and converting values. Use abn(), jajab(), qoraal(), and bool() for explicit conversions.
nooc() – Inspect a Type
Use nooc() to get the type name of a value.
type_checking.sop
type_checking.sop
door natiijo = nooc(42) // "abn" door natiijo2 = nooc("abc") // "qoraal" door natiijo3 = nooc(3.14) // "jajab"
nooc() returns one of these type names:
| Value | nooc() |
|---|---|
42 | abn |
3.14 | jajab |
"abc" | qoraal |
run / been | bool |
[1, 2] | teed |
{a: 1} or a class instance | walax |
| Function | hawl |
maran | maran |
Type Conversion Functions
The following table shows common conversions:
| Conversion | Function | Example |
|---|---|---|
| Int → String | qoraal() | qoraal(42) |
| String → Int | abn() | abn("123") |
| Float → String | qoraal() | qoraal(3.14) |
| String → Float | jajab() | jajab("3.14") |
| Int → Float | jajab() | jajab(5) |
| Float → Int | abn() | abn(4.9) → 4 (truncates) |
| Any → Bool | bool() | bool(1) → run, bool(0) → been |
bool() Rules
bool() returns been for 0, 0.0, "", maran, been, an empty list [], an empty object {}, and the strings "false" and "False". All other values produce run, including the string "been".
bool_rules.sop
qor(bool(0)) // been qor(bool("")) // been qor(bool([])) // been qor(bool("false")) // been qor(bool("salaan")) // run qor(bool("been")) // run
Example
type_conversion_example.sop
// Integer to string abn int_value = 42 qoraal int_str = qoraal(int_value) qor("Integer to string: " + int_str + " (Type: " + nooc(int_str) + ")") // String to decimal qoraal decimal_string = "3.14159" jajab converted_decimal = jajab(decimal_string) qor("String to decimal: " + converted_decimal + " (Type: " + nooc(converted_decimal) + ")") // Decimal to integer (truncation) jajab decimal_num = 42.75 abn int_from_decimal = abn(decimal_num) qor("Decimal to integer (truncation): " + int_from_decimal)
Input from gelin() is a string. Convert it to the type you need before using it in numeric calculations.