Created
May 5, 2022 04:59
-
-
Save yitonghe00/3e1c4e5059c431aaeee537f8937b0cc7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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