Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yitonghe00/3e1c4e5059c431aaeee537f8937b0cc7 to your computer and use it in GitHub Desktop.
Save yitonghe00/3e1c4e5059c431aaeee537f8937b0cc7 to your computer and use it in GitHub Desktop.
// Represent Egg arrays with JavaScript arrays
topScope.array = (...elements) => {
return elements;
};
topScope.length = (array) => {
return array.length;
};
topScope.element = (array, n) => {
return array[n]
};
run(`
do(define(sum, fun(array,
do(define(i, 0),
define(sum, 0),
while(<(i, length(array)),
do(define(sum, +(sum, element(array, i))),
define(i, +(i, 1)))),
sum))),
print(sum(array(1, 2, 3))))
`);
// → 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment