/Queen

Primary LanguageJavaScript

Queen Logo

Welcome to Queen

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!

Try it out

To produce an abstract syntax tree, use the command:

npm install
npm start <absoulte_path_to_file>

Features

  • 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

Emojis

πŸ‘‘ - start a function
πŸ–¨ - print
😑 - error message
πŸ•³ - _
πŸš€ - =
🍭 - |
πŸ€” - if
❗️- not
πŸ’πŸΌ - ||
⚑️ - cons
πŸ’© - comment

Example Problems

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;
};