Bottles of Beer Song in Magenta
~~ Classic Beer Song
task beerSong: Vacant() ->
String bottles;
Integer i = 99;
while [i >= 1] ->
if [i == 1] ->
bottles = "bottle";
<-
if [i > 1] ->
bottles = "bottles";
<-
emit(i + " " + bottles + " of beer on the wall,");
emit(i + " " + bottles + " of beer,");
emit("Take one down, pass it around,");
i = i - 1;
emit(i + " bottles of beer on the wall!");
<-
<-
git clone https://github.com/angelina-tsuboi/Magenta.git
cd Magenta/src
./rm-gen.sh && ./run.sh FILE_NAME.mgnta
block Robot ->
Integer age = 3;
String name = "Bob";
task greeting: Vacant() ->
emit "Hello, my name is " + age;
<-
<-
task getSum: Integer(Integer one, Integer two) ->
Integer sum = one + two;
pass sum;
<-
- Boolean
Boolean bool = true;
Boolean bool2 = false;
- Integer
Integer int = 2;
Integer age = 14;
- Decimal
Decimal dec = 289.3;
Decimal pi = 3.141592;
- String
String alphabet = "abcdef";
String intro = "Hello World";
- Vacant
task sayHello: Vacant ->
emit("hello");
<-
- Emit: prints out a value
emit("Hello World!");
emit("Emit prints stuff out!");
- Pass: returns value from function or method
task getPi: Decimal() ->
pass 3.14;
<-
- One-line comments:
~~ This is a comment
- Multi-line comments:
~*
This is a
multi-line
comment
block!
*~
task evenOrOdd: Vacant(Integer number) ->
if(number % 2 == 0) ->
emit("Number is even");
pass;
<-
emit("Number is odd");
<-
block Car ->
Decimal fuel = 17.89;
Integer miles = 88;
String brand = "Mercedes";
task introduce: Vacant() ->
emit("This is a " + brand + " car!");
<-
task getFuel: Decimal() ->
pass fuel;
<-
<-