Cast: Difference between revisions
Content added Content deleted
No edit summary |
("Better category ordering, add redirects to categories, fix pseudo-adverb categories") |
||
(6 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{primitive|x$y}} |
{{primitive|x$y<br>x@y|in=K6(<code>$</code>), K9(<code>@</code>)}} |
||
'''cast''', also known as '''dollar''', casts a value to a different datatype based on a given value. The required casting value for <code>x</code> varies between dialects. |
'''cast''', also known as '''dollar''', casts a value to a different datatype based on a given value. The required casting value for <code>x</code> varies between dialects. |
||
Line 26: | Line 26: | ||
`c$72 101 108 108 111 46 |
`c$72 101 108 108 111 46 |
||
"Hello." |
"Hello." |
||
`f`i |
`f`i$31 |
||
31 31 |
31 31 |
||
</pre> |
</pre> |
||
Line 42: | Line 42: | ||
</pre> |
</pre> |
||
= References = |
= References = |
||
[[Category:Verbs]] |
|||
[[Category:Operator verbs]] |
|||
[[Category:Primitives]] |
Latest revision as of 06:14, 9 July 2022
Cast
x$y
x@y
x@y
Supported in | K6($ ), K9(@ )
|
cast, also known as dollar, casts a value to a different datatype based on a given value. The required casting value for x
varies between dialects.
The cast primitive is fully atomic.
K6[edit]
Uses symbols to indicate cast target.
Symbol | Type |
---|---|
`i |
Integer |
`b |
Boolean |
`f |
Float |
`c |
Character |
`i$"Hello." 72 101 108 108 111 46 `c$72 101 108 108 111 46 "Hello." `f`i$31 31 31
K3[1][edit]
0$"123" /parse as int 123 0.0$"123.45678" /parse as float 123.45678 0.0$"123.456789999999" /parse as float (note that default precision (\p) is set to 7) 123.4568 `$"zzz" /convert string to symbol `zzz