Queen is a JavaScript ES6 language with OCaml's pattern matching and first class functions. Coders everywhere can create and complete projects on their smartphones while enjoying the expressiveness of emojis. Queen is also a great way to excite kids about computer science, once they see how fun and creative it can be! We hope you enjoy seeing your functions come to life as much as we do!
To produce an abstract syntax tree, use the command:
npm install
npm start <absoulte_path_to_file>
- Emoji keywords
- First class functions
- Higher order functions
- Anonymous functions
- Pattern matching
- No while loops (pattern matching instead)
- No for loops (pattern matching instead)
- Static typing
π - start a function
π¨ - print
π‘ - error message
π³ - _
π - =
π - |
π€ - if
βοΈ- not
ππΌ - ||
β‘οΈ - cons
π© - comment
QUEEN:
π string helloWorld π π¨ "Hello World!
JS:
console.log("Hello World!");
QUEEN:
'π float fib (x: int) π
match x with
π [0] -> 0
π [1] -> 1
π π³ -> (let a π x - 1 in let b
π x - 2 in let z
π fib (a) in let y
π fib (b) in y + z)
JS:
myRecursiveFunction = (n) => {
if (n > 0) {
return myRecursiveFunction(n-1);
} else {
return n;
}
};
QUEEN:
π int length (l : string) π
match l with
π hd β‘οΈ [] β 1
π hd β‘οΈ tl β 1 + length(tl)
JS:
let l = [1, 2, 3];
let lengthl = l.length;
QUEEN:
π€ (a π 0 ππΌ b π 0) then a
elseπ€ (c π 0) then c
JS:
if (a == 0 || b == 0) {
return a
} else if (c == 0) {
return c
}
QUEEN:
π string reverse (l : string) π
match l with
π [] β []
π hd β‘οΈ tl β reverse(tl) @ [hd]
JS:
let fruits = [βstrawberriesβ, βbananasβ, blueberriesβ, βraspberriesβ];
let reversed = fruits.reverse();
QUEEN:
π int change (n : int) π
(let quarters π n/25 in
let dimes π (n mod 25)/10 in
let nickels π ((n mod 25) mod 10)/5 in
let pennies π (((n mod 25) mod 10) mod 5) in
[quarters;dimes;nickels;pennies])
JS:
var change = function (n) {
var changeAmt = [],
total = 0;
[25, 10, 5, 1].forEach(function(coin) {
while (total + coin <= n) {
changeAmt.push(coin);
total += coin;
}
});
return changeAmt;
};