yarn install
yarn lint
andyarn test
ts-node src/repl.ts
to start the REPL
➜ ts-node src/repl.ts
> 1 + 2 * 3 ** 5.2
606.4252366531416
> function add(a, b) { return a + b }
undefined
> add(1, 2)
3
> function asdf
SyntaxError: Expected '(' delimiter but got 'End' delimiter.
> function foo() asdf
SyntaxError: Expected '{' delimiter but got 'Identifier' literal.
function add(a, b) {
return a + b
}
add(1, 2) * 2 - 1 # Evaluates to 5
function fib(n) {
if (n < 2) {
return n
}
return fib(n - 2) + fib(n - 1)
}
foo = function() {
x = 1
# Yes! It's a function that returns another function ;)
return function() {
return x + 2
}
}
bar = foo()
bar()
a = 1
function foo() {
a = 2 # Should replace value in the parent scope
b = 1 # Should be accessible only in the current scope
function bar() {
c = 3 # Should be accessible only in the current scope
return a + b + c
}
return bar()
}
d = foo()
a = 1
function add() {
# Currently a is 1, but later its value will be changed
return a + 1
}
firstResult = add()
# => 2
a = 2
secondResult = add()
# => 3