|
| 1 | +--- |
| 2 | +title: "Builtins" |
| 3 | +slug: "builtins" |
| 4 | +description: "" |
| 5 | +summary: "" |
| 6 | +date: 2026-02-04T19:06:43+02:00 |
| 7 | +lastmod: 2026-02-04T19:06:43+02:00 |
| 8 | +draft: false |
| 9 | +weight: 410 |
| 10 | +toc: true |
| 11 | +seo: |
| 12 | + title: "" # custom title (optional) |
| 13 | + description: "" # custom description (recommended) |
| 14 | + canonical: "" # custom canonical URL (optional) |
| 15 | + noindex: false # false (default) or true |
| 16 | +--- |
| 17 | + |
| 18 | +## toString |
| 19 | + |
| 20 | +--- |
| 21 | +`(toString value)` |
| 22 | +Convert a value to a string |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +#### Parameter |
| 27 | +- `value`: anything |
| 28 | + |
| 29 | + |
| 30 | +#### Example |
| 31 | +{{< highlight_arkscript >}} |
| 32 | +(print (toString "abc")) # "abc" |
| 33 | +(print (toString 1)) # "1" |
| 34 | +(print (toString (fun () ()))) # "Function@1" |
| 35 | +(print (toString print)) # "CProcedure" |
| 36 | +(print (toString [])) # "[]" |
| 37 | +(let x 1) (print (toString (fun (&x) ()))) # "(.x=1)" |
| 38 | +(print (toString (dict 1 2 3 4))) # "{1: 2, 3: 4}" |
| 39 | +(print (toString nil)) # "nil" |
| 40 | +(print (toString true)) # "true" |
| 41 | +(print (toString false)) # "false" |
| 42 | +{{< /highlight_arkscript >}} |
| 43 | + |
| 44 | +## type |
| 45 | + |
| 46 | +--- |
| 47 | +`(type value)` |
| 48 | +Get the type of a given value as a string |
| 49 | + |
| 50 | + |
| 51 | + |
| 52 | +#### Parameter |
| 53 | +- `value`: anything |
| 54 | + |
| 55 | + |
| 56 | +#### Example |
| 57 | +{{< highlight_arkscript >}} |
| 58 | +(print (type "abc")) # "String" |
| 59 | +(print (type 1)) # "Number" |
| 60 | +(print (type (fun () ()))) # "Function" |
| 61 | +(print (type print)) # "CProc" |
| 62 | +(print (type [])) # "List" |
| 63 | +(let x 1) (print (type (fun (&x) ()))) # "Closure" |
| 64 | +(print (type (dict 1 2 3 4))) # "Dict" |
| 65 | +(print (type nil)) # "Nil" |
| 66 | +(print (type true)) # "Bool" |
| 67 | +(print (type false)) # "Bool" |
| 68 | +{{< /highlight_arkscript >}} |
| 69 | + |
| 70 | +## nil? |
| 71 | + |
| 72 | +--- |
| 73 | +`(nil? value)` |
| 74 | +Check if a value is nil |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | +#### Parameter |
| 79 | +- `value`: anything |
| 80 | + |
| 81 | + |
| 82 | +#### Example |
| 83 | +{{< highlight_arkscript >}} |
| 84 | +(print (nil? "abc")) # false |
| 85 | +(print (nil? 1)) # false |
| 86 | +(print (nil? (fun () ()))) # false |
| 87 | +(print (nil? print)) # false |
| 88 | +(print (nil? [])) # false |
| 89 | +(print (nil? (dict 1 2 3 4))) # false |
| 90 | +(print (nil? nil)) # true |
| 91 | +(print (nil? true)) # false |
| 92 | +(print (nil? false)) # false |
| 93 | +{{< /highlight_arkscript >}} |
| 94 | + |
| 95 | +## comparison |
| 96 | + |
| 97 | +--- |
| 98 | +`(comparison a b)` |
| 99 | +Compare two values and return true or false |
| 100 | + |
| 101 | +**Note**: Comparing two values (using `<`, `>`, `<=`, `>=` and `=`) with a different type will always return false |
| 102 | + |
| 103 | + |
| 104 | +#### Parameters |
| 105 | +- `a`: first value |
| 106 | +- `b`: second value |
| 107 | + |
| 108 | + |
| 109 | +#### Example |
| 110 | +{{< highlight_arkscript >}} |
| 111 | +(print (< "abc" "def")) # true, string are compared lexicographically |
| 112 | +(print (< 2 1)) # false |
| 113 | +(print (> 3 -5.5) # true |
| 114 | +(print (> "Hello" "")) |
| 115 | +(print (<= [] [1 2])) # true, lists are compared lexicographically |
| 116 | +(print (<= [1 2] [1 0])) # false |
| 117 | +(print (<= [1 2] [10])) # true |
| 118 | +(print (>= 5 5)) # true |
| 119 | +(print (= false 5)) # false |
| 120 | +(print (!= false 5)) # true |
| 121 | +{{< /highlight_arkscript >}} |
| 122 | + |
| 123 | +## not |
| 124 | + |
| 125 | +--- |
| 126 | +`(not value)` |
| 127 | +Convert a value to a boolean and invert it |
| 128 | + |
| 129 | + |
| 130 | + |
| 131 | +#### Parameter |
| 132 | +- `value`: anything |
| 133 | + |
| 134 | + |
| 135 | +#### Example |
| 136 | +{{< highlight_arkscript >}} |
| 137 | +(print (not "")) # true |
| 138 | +(print (not "a")) # false |
| 139 | +(print (not 0)) # true |
| 140 | +(print (not 1)) # false |
| 141 | +(print (not [])) # true |
| 142 | +(print (not [1 2])) # false |
| 143 | +(print (not nil)) # true |
| 144 | +(print (not true)) # false |
| 145 | +(print (not false)) # true |
| 146 | +(print (not (dict))) # true |
| 147 | +(print (not (dict "a" 1))) # false |
| 148 | +{{< /highlight_arkscript >}} |
| 149 | + |
| 150 | +## hasField |
| 151 | + |
| 152 | +--- |
| 153 | +`(hasField c field)` |
| 154 | +Check if a closure has a given field |
| 155 | + |
| 156 | + |
| 157 | + |
| 158 | +#### Parameters |
| 159 | +- `c`: closure |
| 160 | +- `field`: string, field name to look for |
| 161 | + |
| 162 | + |
| 163 | +#### Example |
| 164 | +{{< highlight_arkscript >}} |
| 165 | +(let x 1) |
| 166 | +(let b "hello") |
| 167 | +(let closure (fun (&x &b) ())) |
| 168 | +(print (hasField closure "x")) # true |
| 169 | +(print (hasField closure "b")) # true |
| 170 | +(print (hasField closure "B")) # false, field names are case-sensitive |
| 171 | +{{< /highlight_arkscript >}} |
| 172 | + |
| 173 | + |
| 174 | + |
| 175 | +{{< highlight_scripts >}} |
0 commit comments