reverse
Builtin index · Collections & strings
result = reverse(x)
Input: x · Output: result
What it is
x is a Str, List, Vec, or Mask. Unicode-aware character reversal for a Str (same type back); element-order reversal for a List/Vec/Mask (same type and shape back).
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = reverse(x) | x Str, List, Vec, or Masknot documented yet | result — | Returns exactly the same type and length as x. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
s = "Hello, Qu World!"
print(mid(s, 7, 2)) # "Qu"
print(left(s, 5)) # "Hello"
print(right(s, 6)) # "World!"
print(reverse("abc")) # "cba"
print(lower("SHOUT")) # "shout"
print(ucase("shout")) # "SHOUT"
print(lcase("SHOUT")) # "shout"
print(toupper("mix")) # "MIX"
print(tolower("MIX")) # "mix"
print(capitalize("ada lovelace")) # "Ada lovelace"
print(ltrim(" padded")) # "padded"
print(rtrim("padded ") + "|") # "padded|"
print(pad_right("ab", 5, ".")) # "ab..."
print(compare("apple", "banana")) # -1
print(asc("A")) # 65
Qu
Hello
World!
cba
shout
SHOUT
shout
MIX
mix
Ada lovelace
padded
padded|
ab...
-1
... 1 more linesfrom collections-strings
How it works
reverse(x) — for a Str, the unicode-aware reversed string; for a List, element order reversed; for a Vec/ Mask, the same element-order reversal fliplr/mirror already provide under those names (verified equivalent to fliplr on a plain vector) — reverse is simply this codebase's first conventionally-named entry point that also covers Str/List, not a second, divergent algorithm for the numeric case.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.