0% found this document useful (0 votes)
6 views1 page

Tutorial _ Rockstar

This document is a tutorial for Rockstar, a programming language designed to resemble song lyrics. It covers basic concepts such as syntax, variables, types, expressions, and control structures, emphasizing its unique features like poetic numbers and ninja strings. The tutorial includes interactive examples to help users learn and experiment with the language's capabilities.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Tutorial _ Rockstar

This document is a tutorial for Rockstar, a programming language designed to resemble song lyrics. It covers basic concepts such as syntax, variables, types, expressions, and control structures, emphasizing its unique features like poetic numbers and ninja strings. The tutorial includes interactive examples to help users learn and experiment with the language's capabilities.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Tommy used to work on the docs

Home Docs Try It News Merch Community

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:

1 print "hello world"


2
Try It 

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.

1 Say "Hello London..."


2 Shout "Hello, London!"
3 SCREAM "I SAID HELLO, LONDON!"
4 whisper "...do you wanna get rocked?"
5
Try It 

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 let 1

1 My heart is 123
2 Let your love be 456
3 Put 789 into the night
4
5 Shout my heart. Scream your love. Whisper the night.
6
Try It 

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:

1 Doctor Feelgood is 123


2 Johnny B. Goode is 456
3 Billie Jean is 789
4
5 Shout Doctor Feelgood! Whisper Johnny B. Goode? Say Billie Jean.
6
Try It 

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:

1 x is 123
2 let myVariable be 456
3 put 789 into customerId
4 print x. print myVariable. print customerId.
5
6
7
Try It 

Types and Expressions


Rockstar supports numbers and basic arithmetic expressions:

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

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 :

1 The price is 5. The tax is 4. The discount is 3. The quantity is 2.


2 The distance is 20. The time is 10.
3
4 Let the total be the price plus the tax. Print the total.
5 Let the total be the price minus the discount. Print the total.
6 Let the cost be the quantity times the price. Print the cost.
7 Let the speed be the distance divided by the time. Print the speed.
8
9
Try It 

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.

1 My heart is 1. The night is 2.


2 The wings are 3. Your love is 4.
3 A hope is 5. A girl is 6.
4 A boy is 7. A dream is 8.
5
6 Let Tommy be a boy with a dream. Say Tommy. (prints: 15)
7 Let Gina be a girl without a hope. Say Gina (prints: 1)
8 Whisper the wings of the night (prints: 6)
9 Scream a dream over the night (prints: 4)
10
Try It 

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.

1 Print "banana" times -1


2 Print "banana" divided by "a"
3 Print "yeah" plus true plus null plus 2 plus " yeah!"
4 Print "Bon Joviality" - "ality"
5 Print "Heartbreak" * 0.5
6 Print "AD" times "C"
7 Print "Motley" times "Crue"
8
Try It 

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:

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


2 Scream Ricky.
3
Try It 

…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:

1 Tommy was 123


2 Gina's working the diner all day.
3 Print Tommy. Shout Gina.
4 Tommy's with Gina.
5 Print Tommy.
6
Try It 

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:

1 My string is "hey, this is mine!"


2 Your string is "look, ""nested quotes"" - see?"
3 Gina says we gotta hold on to what we've got.
4
5 Print my string.
6 Shout your string.
7 Whisper Gina.
8
9
Try It 

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.

1 Listen to the night


2 If the night ain't nothing
3 Shout the night
4 Otherwise
5 Shout "no input provided"
6 Baby
7
8
Try It 

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.

<variable> holds <poetic number> - will convert <poetic number> to the Unicode character with the corresponding code point, and
assign variable to the resulting string.
rock <variable> <number> - will add characters to the end of a string based on their code points - and because you can use the like
keyword:
rock <variable> like <poetic_number> will build a string out of pure poetry.

1 My soul is empty
2 Rock my soul with 70 (ASCII code for F)
3 Rock my soul 105 (ASCII i)
4 Rock my soul with 122, 122 (ASCII z, z)
5
6 The night holds Eddie's guitar ( = 66 = B)
7 Rock the night like a heartbroken heroine ( = 117 = u)
8 Fury is a rage-twisted thundercloud ( = 122 = z)
9 Rock the night with fury, fury (z, z)
10
11 Whisper my soul with the night (prints: FizzBuzz)
12
Try It 

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 .

1 X is 0
2 Until X is 10
3 Write X with ": "
4 If X is 5 Print "X is 5!" Else Print "X is not 5" (one-line If statement)
5 If X is 2
6 Print X with " is 2"
7 End (end of multi-line If block)
8 Put X plus 1 into X
9 End (end of Until loop)
10
Try It 

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.

1 My love is nothing
2 While my love ain't like a rose,
3 Whisper my love
4 If my love is like fire
5 Break my heart, yeah
6 Build my love up, baby
7
8 My love is nothing
9 While my love ain't like a rose,
10 Build my love up
11 If my love is like fire
12 Take me to the river, baby
13 Whisper my love, yeah
14
15
16
Try It 

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

1 If true
2 if true
3 if true
4 if true
5 if true
6 Shout "Yep, it's DEFINITELY true"
7 Oooh yeah baby
8
Try It 

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.

1 My variable is true
2
3 If it's true print "it's true!"
4
5
6 The counter is 0
7 While it's less than 10
8 Shout it
9
10 Build it up, baby.
11
12
13 Gina's empty
14 Until she's like a star
Build her up
Whisper her, baby

Try It 

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:

1 Rock you like a hurricane


2

Try It 

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:

1 X is 1
2
3 If x = 1 print "Axl"
4 If X is 1 print "Slash"
5
6 If X != 2 print "Izzy"
7 If X is not 2 print "Dizzy"
8 If X isn't 2 print "Duff"
If X ain't nothing print "Matt"

Try It 

..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.

1 X is 5
2
3 If x >= 5 print "Ozzy"
4 If x <= 5 print "Tony"
5
6 If x < 6 print "Geezer"
7 if x > 4 print "Bill"
8
9
10 My heart is crying
11 The sky is on fire
12
13 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"

Try It 

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

1 My heart is true
2
3 Your love is true
4 His dreams are lies
5
6 Her heart is wrong
7
8 If my heart and your love shout "Joan"
9
10 If my heart or her dreams shout "Cherie"
11 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"
Try It 

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:

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

Try It 

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> .

1 Sum takes x, y
2
3 Give back x + y
4 End
5
6
7 Print sum taking 5, 6
8
9
10 Product takes x, y giving x * y
11
12 Foo is 5
13
Bar is 6
Print product taking foo, bar

Try It 

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.

1 The jungle takes Axl, Slash & Duff n' Izzy, and Steven
2
3 Write Axl. Write Slash. Write Duff. Write Izzy. Print Steven.
4 Yeah.
5
6
7 Call the jungle with "Oh, " & "oh " n' "oh, ", and "sweet child", " o' mine"
8
9
10 Led Zeppelin takes Robert and Jimmy and John Paul and Bonzo
11 Give back Robert with Jimmy with John Paul with Bonzo
12 Baby

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

Try It 

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:

1 Rock my array
2
3 Print my array (prints: [ ])
4
5 Rock the night with 1, 2, 3
6
7 Print the night (prints: [ 1, 2, 3 ])
8

Try It 

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

1 Rock my array with 1, 2, 3


2
3 While my array ain't empty
4 Roll my array into the result
5 Print the result
6
7 Yeah
8 (prints:
9
10 1
11 2
3
)

Try It 

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 :

1 Rock your stack with 1, 2, 3, 4, 5


2
3 Shout pop your stack (prints: 5)
4 Shout roll your stack (prints: 1)
5 Shout pop your stack (prints: 4)
6
7 Shout roll your stack (prints: 2)
8 Shout your stack (prints: [ 3 ])
9
10 Pop your stack
Shout your stack (prints: [ ])

Try It 

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:

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 :

1 Split "a,b,c" into the array


2
3 Shout the array (prints: [ "a", ",", "b", ",", "c" ])
4 Shout the array + 0 (prints: 5)
5
6
7 Split "a,b,c" into the array with ","
8 Shout the array (prints: [ "a", "b", "c" ])
9
10 Shout the array + 0 (prints: 3)
11
12
13 My life says heartbreak
14 Cut my life into pieces
Shout pieces (prints: [ "h", "e", "a", "r", "t", "b", "r", "e", "a", "k" ])
Shout pieces + 0 (prints: 10)

Try It 

Joining Arrays

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

1 Let the string be "abcde"


2
3 Split the string into the tokens
4 Join the tokens with ";"
5
6 Print the tokens (prints: a;b;c;d;e)
7
8 The input says hey now hey now now
9
10 Split the input into the words with " "
11 Unite the words into the output with "! "
12
13 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)

Try It 

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.

1 Let X be "123.45"
2
3 Shout X + X (prints: 123.45123.45)
4 Cast X with 10
5
6 Shout X + X (prints: 246.9)
7 Let X be "FF"
8 Cast X with 16 (cast using base 16)
9
10 Shout X (prints: 255)
11
12
13 Cast 65 into result. Shout result (prints: A)
14
15 Cast result. Shout result (prints: 65)
16
17
18 Cast 1046 into result. Shout result (prints: Ж)
19
20
21 Guitar is "1F3B8". Cast it with 16. Cast it.
22 Shout it. (prints: 🎸)
23

The string is "32"


Cast the string into the codes
Write the codes at 0 (writes: 51)
Write the codes at 1 (writes: 50)

Try It 

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

1 My boolean is true
2
3 My number is 12.34
4 The night is empty
5
6
7 My boolean is with the night
8 Shatter my boolean
9
10 Whisper my boolean (prints: [ "t", "r", "u", "e" ])
11
12 My number is with the night
13
Shatter my number
Whisper my number (prints: [ "1", "2", ".", "3", "4" ])

Try It 

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. ↩

rockstar created by dylan beattie • copyright © 2018-2024 dylan beattie • hello@codewithrockstar.com

code of conduct • code on github • analytics by fathom

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy