Rockstar

Tommy used to work on the docs

Do You Wanna Get Rocked?

Welcome! In this tutorial, you’ll learn the basics of Rockstar, and find out what makes Rockstar one of the world’s most delightfully pointless programming languages.

Hello, World

“Hello, World” in Rockstar looks like this:

print "hello world"

All the examples in this tutorial are interactive: click on “Try It ” to open the control panel, then press the “Rock ” button to run the code and see what it does.

Because Rockstar’s designed to write programs that look like song lyrics, it’s very relaxed when it comes to syntax. Almost everything in Rockstar is case-insensitive, and most keywords have several different aliases so you can pick the one that suits the mood of your program.

Say "Hello London..."
Shout "Hello, London!"
SCREAM "I SAID HELLO, LONDON!"
whisper "...do you wanna get rocked?"

Try it out. Edit the example above and replace London with your home town.

Variables in Rockstar

A variable stores a value so you can refer back to it later. In most programming languages, a variable name can’t contain spaces, so programmers have to use names like customerTaxPayable or year_end_date, or customer-shipping-address.

Rockstar is not like most programming languages: if you want to put spaces in your variables, you go right ahead. After all, nobody ever wrote a power ballad about customerTaxPayable.

Common Variables

Common variables in Rockstar start with a, the, my, your, their, his or her. To assign a value to a variable, use put, is, or let1

My heart is 123
Let your love be 456
Put 789 into the night

Shout my heart. Scream your love. Whisper the night.

You might also notice we’ve got three statements on the same line there. That’s just fine, because each statement ends with full stop - just like regular English. Statements in Rockstar can end with a full stop ., question mark ?, exclamation mark !, semi-colon ;, or a line break.

Proper Variables

Proper variables in Rockstar are two or more words which must all begin with a capital letter. Initials are allowed – Johnny B. Goode – but abbreviations aren’t: you can’t have a variable called Mr. Crowley because Rockstar treats the . in Mr. as the end of a statement:

Doctor Feelgood is 123
Johnny B. Goode is 456
Billie Jean is 789

Shout Doctor Feelgood! Whisper Johnny B. Goode? Say Billie Jean.

Simple Variables

If you really want to, you can use simple variables, which work just like variables in Python, Ruby, and many other programming languages:

x is 123
let myVariable be 456
put 789 into customerId
print x. print myVariable. print customerId.


Types and Expressions

Rockstar supports numbers and basic arithmetic expressions:

Print 1 + 2
Print 3 * 4
Print 5 - 6
Print 7 / 8
Print 1 + 2 * 3 - 4 / 5

Problem is, there’s only one good song about mathematics and Little Boots already wrote it, so all the arithmetic operators in Rockstar support aliases. Instead of +, use plus or with. - can be minus or without, * can be times or of, and / is over or divided by:

The price is 5. The tax is 4. The discount is 3. The quantity is 2.
The distance is 20. The time is 10. 

Let the total be the price plus the tax. Print the total.
Let the total be the price minus the discount. Print the total.
Let the cost be the quantity times the price. Print the cost.
Let the speed be the distance divided by the time. Print the speed.

This is also probably a good time to mention that you can’t use brackets in Rockstar. Well, you can, but they’re used to indicate comments (like this) - because that’s how lyrics work.

My heart is 1. The night is 2.
The wings are 3. Your love is 4.
A hope is 5. A girl is 6.
A boy is 7. A dream is 8.

Let Tommy be a boy with a dream. Say Tommy. (prints: 15)
Let Gina be a girl without a hope. Say Gina (prints: 1)
Whisper the wings of the night (prints: 6)
Scream a dream over the night (prints: 4)

Rockstar will let you add, multiply, subtract and divide just about anything - check out the docs to find out exactly how this works, or just try stuff out and see what happens. Remember, this is a joke language based on Bon Jovi songs. You’re not gonna break anything important.

Print "banana" times -1
Print "banana" divided by "a"
Print "yeah" plus true plus null plus 2 plus " yeah!"
Print "Bon Joviality" - "ality"
Print "Heartbreak" * 0.5
Print "AD" times "C"
Print "Motley" times "Crue"

Poetic Numbers

You notice in the last example, I wrote Let Tommy be a boy with a dream - and not Tommy is a boy with a dream?

Try this:

Ricky was a young boy, he had a heart of stone.
Scream Ricky.

…OK, where did 153231525 come from?

Welcome to one of Rockstar’s most unusual features: poetic literals.

When you initialise a variable using is, was or were, if the thing on the right-hand side doesn’t start with a digit 0-9, or with one of the arithmetic operator keywords (plus, with, etc.) Rockstar treats it as a poetic number. It’ll take the length of each word, modulo 10, and interpret those word lengths as decimal digits.

So Ricky was a young boy, he had a heart of stone, gives us:

a young boy, he had a heart of stone
1   5    3    2  3  1   5   2    5

A poetic number includes everything up to the end of the line, so watch out for statements like Lucy was a dancer. Say Lucy! - that’s not going to print Lucy, it’s going to assign Lucy the value 1634. Poetic numbers count hyphens (-) and ignore all other punctuation, so you can use phrases like cold-hearted for the digit 2 instead of having to think of 12-letter words.

If you want to use a poetic number anywhere else in your Rockstar program, prefix it with the like keyword: Let my variable be like a rolling stone will initialise my variable with the value 175.

Viewing the Parse Tree

Features like poetic numbers can make it hard to figure out exactly what a Rockstar program is doing, so the Rockstar engine that runs on this website also allows you to see the parse tree - an abstract representation of the structure of your Rockstar program. Try clicking “Parse ” here and see what you get:

Tommy was 123
Gina's working the diner all day.
Print Tommy. Shout Gina.
Tommy's with Gina.
Print Tommy.

Strings

No, not that kind of strings. Strings are how Rockstar handles text. A string in Rockstar is surrounded by double quotes; to include double quotes in a string, use two sets of double quotes. You can also use poetic string syntax using the says keyword:

My string is "hey, this is mine!"
Your string is "look, ""nested quotes"" - see?"
Gina says we gotta hold on to what we've got.

Print my string.
Shout your string.
Whisper Gina.

Reading Input

To read input from the console, use listen. Listen on its own will read a line of input from STDIN and discard it. Listen to <variable> will read the next line of input from STDIN and store it in <variable> as a string.

For all kinds of complicated reasons, the Rockstar engine that runs on this website can’t prompt you for input, so you’ll need to provide the input in advance using the text box below the Rockstar editor.

Listen to the night
If the night ain't nothing
Shout the night
Otherwise
Shout "no input provided"
Baby

Ninja Strings

The problem with literal strings is they often don’t fit the mood of the song you’re trying to write. FizzBuzz is all well & good, but shouting the word “fizz” in the middle of power ballad just isn’t gonna work.

To get around this, Rockstar includes a feature that lets you build strings without ever having to refer to them directly: we call these ninja strings, because like ninjas, they are both stealthy and awesome.

My soul is empty
Rock my soul with 70 (ASCII code for F)
Rock my soul 105 (ASCII i)
Rock my soul with 122, 122 (ASCII z, z)

The night holds Eddie's guitar ( = 66 = B)
Rock the night like a heartbroken heroine ( = 117 = u)
Fury is a rage-twisted thundercloud ( = 122 = z)
Rock the night with fury, fury (z, z)

Whisper my soul with the night (prints: FizzBuzz)

Booleans, Null, and Mysterious

As well as numbers and strings, Rockstar has boolean types, null, and mysterious.

Booleans are true - aliases right, yes, and ok - and false, with its aliases wrong, no, and lies.

null means a value that’s missing or not available yet - aliases nothing, nowhere, nobody.

Rockstar also has a type called mysterious, which works like undefined in JavaScript; it’s the language’s way of saying “not only do I not know what this is, I don’t even know how to tell you what’s wrong with it.”

Conditionals and Loops

Conditionals in Rockstar use the if keyword, alias when, and the else / otherwise keywords. Loops begin with while or until.

X is 0
Until X is 10
Write X with ": "
If X is 5 Print "X is 5!" Else Print "X is not 5" (one-line If statement)
If X is 2
Print X with " is 2"
End (end of multi-line If block)
Put X plus 1 into X
End (end of Until loop)

Multi-line conditionals and loops have to end with an end of block. In previous versions of Rockstar, this had to be a blank line. Rockstar 2 adds an explicit end keyword, along with the aliases yeah and baby.

To exit a loop immediately, use the break keyword. To skip the rest of the current iteration and restart the loop, use the continue keyword or the alias take

break and take in Rockstar are wildcard keywords: you can follow them with anything you like, and everything up until the next end of statement (,.!?;) or newline will be ignored. This is mainly because the original Rockstar draft used take it to the top as a synonym for continue, which sounded cool but is actually incredibly stupid, even by Rockstar standards.

My love is nothing
While my love ain't like a rose,
Whisper my love
If my love is like fire
Break my heart, yeah
Build my love up, baby

My love is nothing
While my love ain't like a rose,
Build my love up
If my love is like fire
Take me to the river, baby
Whisper my love, yeah


Oh, ooh, oooh yeah, baby

You can also end a Rockstar block with the keyword oh. Ooh ends two blocks, oooh ends three blocks, and so on until you get bored or your computer runs out of memory. Think of this like the Rockstar equivalent of }}}} in C-style languages, or the ))))) that ends most Lisp programs.

If true
if true
if true
if true
if true
Shout "Yep, it's DEFINITELY true"
Oooh yeah baby

Pronouns

Oh, yes, Rockstar has pronouns.2 In natural languages, a pronoun is just a way to refer to something based on context, instead of explicitly having to name things every time - it’s the difference between “Tommy put his guitar in the back of his car, he drove out into the night” and “Tommy put Tommy’s guitar in the back of Tommy’s car, Tommy drove out into the night”.

Rockstar supports the pronouns it, he, she, him, her, they, them, and a whole lot more - see the docs for the full list.

A Rockstar pronoun refers to the last variable which was assigned, or the last variable that appeared as the left-hand side of the test in a conditional or loop statement. That sounds complicated, but it’s not: most of the time, you can just use it, him or her in your programs as you would in regular English, and it’ll probably work.

My variable is true
If it's true print "it's true!"

The counter is 0
While it's less than 10
Shout it
Build it up, baby.

Gina's empty
Until she's like a star
Build her up
Whisper her, baby

Remember that although Rockstar has many different pronouns, at any given point in your program, every pronoun points to the same variable – you can’t have him, her and it pointing to different things. Trying to update pronoun subjects based on assumptions about gendered names would be hard enough even if rock’n’roll wasn’t full of dudes called Tracii, Alice and Rachel… you know that on the cover of “Rumours” by Fleetwood Mac, Stevie is the woman and Lindsay is the man? Yeah. You’re gonna have to keep track of your own pronouns.

The combination of pronouns and ninja strings means that if you ever really need to push an ASCII DC3 control code onto the end of a string, you can do it using this line of code:

Rock you like a hurricane

Equality and Comparisons

You might have noticed we’ve started using expressions like X is 5 in our if and while loops. Rockstar supports all the logical, equality and comparison operators you’d expect to find in a proper programming language:

X is 1
If x = 1 print "Axl"
If X is 1 print "Slash"
If X != 2 print "Izzy"
If X is not 2 print "Dizzy"
If X isn't 2 print "Duff"
If X ain't nothing print "Matt"

..hang on, what happened to Dizzy? not in Rockstar is a unary operator. X is not 2 is going to evaluate not 2 first - and 2 in Rockstar is truthy, so not 2 is falsey, and then it’ll compare X is falsey, and X is 1, and 1 is truthy, and truthy is not equal to falsey… and so 1 is not 2 is actually false. Check out the docs to find out more about things which are truthy, things which are falsey, and how they all fit together.

X is 5
If x >= 5 print "Ozzy"
If x <= 5 print "Tony"
If x < 6 print "Geezer"
if x > 4 print "Bill"

My heart is crying
The sky is on fire
If the sky is greater than my heart print "Vince"
If the sky is as high as my heart print "Mick"
If my heart is weaker than the sky print "Nikki"
If my heart is as low as the sky print "Tommy"

Rockstar also has the Boolean logical operators and, or, nor, and not.

My heart is true
Your love is true
His dreams are lies
Her heart is wrong

If my heart and your love shout "Joan"
If my heart or her dreams shout "Cherie"
If my heart and not her dreams shout "Lita"
If his dreams and her heart shout "Micki"
If his dreams nor her heart shout "Sandy"

Boolean operators in Rockstar will short-circuit - if you evaluate X and Y, and X is false, then Y will never be evaluated because there’s no way X and Y can be true - and, like JavaScript, they’ll return the last evaluated operand necessary to resolve the expression:

Print 3 or 5 (prints: 3)
Print 0 or "rock!" (prints: rock!)
Print false and 1/0 (prints: false) (and never divides by zero)
Print "yeah!" or 1/0 (prints: yeah!) (and never divides by zero)

Functions

Functions in Rockstar are declared with the wants or takes keywords, followed by the list of variables denoting the function’s arguments. If you want to declare a function that has no arguments, specify null, wants nothing or takes nothing.

To call a function, use taking, or call <function> with <arguments>.

Sum takes x, y
Give back x + y
End

Print sum taking 5, 6

Product takes x, y giving x * y

Foo is 5
Bar is 6
Print product taking foo, bar

The arguments in a function call must be separated with commas, ampersands, nactons, or the Oxford comma.

Nacton (n.) The ‘n’ with which cheap advertising copywriters replace the word ‘and’ (as in ‘fish ‘n’ chips’, ‘mix ‘n’ match’, ‘assault ‘n’ battery’), in the mistaken belief that this is in some way chummy or endearing.
“The Meaning of Liff”, Douglas Adams & John Lloyd

Rockstar supports both the UK nacton (fish'n'chips) and the US nacton (Guns n' Roses).

When you declare a function, you can even use and to separate the arguments – because at that point in the language, it can’t possibly mean anything else.

The jungle takes Axl, Slash & Duff n' Izzy, and Steven
Write Axl. Write Slash. Write Duff. Write Izzy. Print Steven.
Yeah.

Call the jungle with "Oh, " & "oh " n' "oh, ", and "sweet child", " o' mine"

Led Zeppelin takes Robert and Jimmy and John Paul and Bonzo
Give back Robert with Jimmy with John Paul with Bonzo
Baby

Print Led Zeppelin taking "Stair", "way", " to ", and "Heaven"

Rock’n’Roll Arrays

Arrays in Rockstar are created with the rock keyword, alias push.

As we’ve already seen when we learned about ninja strings, rocking a string with a number will turn the numbers into a character and append it to the end of the string. This is a special case, because it’s so incredibly useful for building strings.

In all other cases, rock x will turn x from a scalar into a single-element array [ x ], and rock x with y will append y to the end of the array denoted by x.

If you just rock a new variable, it’ll create an empty array. If you rock a new variable with a list of things, it’ll add those things to the new array:

Rock my array
Print my array (prints: [ ])

Rock the night with 1, 2, 3
Print the night (prints: [ 1, 2, 3 ])


Naturally, if you can rock, you can roll. Roll will remove and return the first element of the array.

Rock my array with 1, 2, 3
While my array ain't empty
Roll my array into the result
Print the result
Yeah
(prints:
1
2
3
)

Pop? Really?

Yes, pop. If you rock and roll arrays, they work like queues - first in, first out. If you want your array to behave like a stack, use push and pop:

Rock your stack with 1, 2, 3, 4, 5
Shout pop your stack (prints: 5)
Shout roll your stack (prints: 1)
Shout pop your stack (prints: 4)
Shout roll your stack (prints: 2)
Shout your stack (prints: [ 3 ])
Pop your stack
Shout your stack (prints: [ ])

push is actually an alias for rock - it adds the provided element to the end of the array; roll removes and returns the last element, while pop removes and returns the first element.

Conversions and Mutations

Finally, Rockstar has a handful of built-in functions for doing useful things. These operations can either act in place, mutating the variable passed to them, or leave the result in a target variable and leave the source unmodified:

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

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)

If you just want to convert a value into a string, add it to the empty string:

My boolean is true
My number is 12.34
The night is empty

My boolean is with the night
Shatter my boolean
Whisper my boolean (prints: [ "t", "r", "u", "e" ])

My number is with the night
Shatter my number
Whisper my number (prints: [ "1", "2", ".", "3", "4" ])

Cast

  1. Technically let will declare a new variable in local scope, where put and is will declare or assign a global variable. It’s complicated. See the documentation on variable scope if you really care. 

  2. Rockstar is also woke, fetch, rizz, cheugy, and skibidi, no cap – but that’s not why it has pronouns.