Conversions and Mutations

Conversions and Mutations

Most of Rockstar’s built-in operations can either act in place, modifying the variable passed to them, or leave the result in a target variable and leave the source unmodified:

  • Modify X - acts in-place
  • Modify X into Y - leave X intact, store the result into Y
  • Modify X with Z - act in place, using optional parameter Z
  • Modify X into Y with Z - modify X using Z, store the result in y

Splitting Strings

To split a string in Rockstar, use the cut mutation, or aliases split and shatter.

Split "a,b,c" into the array
Shout the array (prints: [ "a", ",", "b", ",", "c" ])
Shout the array + 0 (prints: 5)

Split "a,b,c" into the array with ","
Shout the array (prints: [ "a", "b", "c" ])
Shout the array + 0 (prints: 3)

My life says heartbreak
Cut my life into pieces
Shout pieces (prints: [ "h", "e", "a", "r", "t", "b", "r", "e", "a", "k" ])
Shout pieces + 0 (prints: 10)

Joining Arrays

To join an array in Rockstar, use the join mutation, or the aliases unite or gather:

Let the string be "abcde"
Split the string into the tokens
Join the tokens with ";"
Print the tokens (prints: a;b;c;d;e)

The input says hey now hey now now
Split the input into the words with " "
Unite the words into the output with "! "
Print the output with "!" (prints: hey! now! hey! now! now!)

Gather the words into the output with "-"
Print the output (prints: hey-now-hey-now-now)

Type Conversions

To convert any value to a string, add it to the empty string.

Let the string be "abcde"
Split the string into the tokens
Join the tokens with ";"
Print the tokens (prints: a;b;c;d;e)

The input says hey now hey now now
Split the input into the words with " "
Unite the words into the output with "! "
Print the output with "!" (prints: hey! now! hey! now! now!)

Gather the words into the output with "-"
Print the output (prints: hey-now-hey-now-now)

The built-in cast function (aka burn) will parse strings into numbers, or convert a number into a Unicode character corresponding to the number’s code point.

Let X be "123.45"
Shout X + X (prints: 123.45123.45)
Cast X with 10
Shout X + X (prints: 246.9)
Let X be "FF"
Cast X with 16 (cast using base 16)
Shout X (prints: 255)

Cast 65 into result. Shout result (prints: A)

Cast result. Shout result (prints: 65)

Cast 1046 into result. Shout result (prints: Ж)

Guitar is "1F3B8". Cast it with 16. Cast it.
Shout it. (prints: 🎸)

The string is "32"
Cast the string into the codes
Write the codes at 0 (writes: 51)
Write the codes at 1 (writes: 50)

Turn Up The Rock: Arithmetic Rounding and String Casing

Rounding and string case conversion in Rockstar is done using turn .

For numbers, Turn up will round up (i.e. towards positive infinity), to the nearest integer; turn down will round down (towards negative infinity) to the nearest integer, and turn round will round to the nearest integer. Bonnie Tyler enthusiasts will be pleased to note that Rockstar accepts turn around as a valid alias.

For strings, turn up will convert the string to UPPERCASE, turn down will convert the string to lowercase.

turn the string around will reverse the string because, well, what else would you expect turn the string around to do?

Both turn <variable> <direction> and turn <direction> <variable> are valid. Turn operations act in-place: they modify the variable directly, and will return the rounded value.

X is 1.2
Turn up X
Shout X (prints: 2)

X is 1.2
Turn down X
Shout X (prints: 1)

The radio's like a siren... the fire has just begun. 
Turn up the radio
Say the radio (prints: 16)

My dad says Motley Crue is lame
Turn it up.
Shout it (prints: MOTLEY CRUE IS LAME)
Turn it down.
Shout it (prints: motley crue is lame)
Turn it around.
Shout it (prints: emal si eurc yeltom)