Created
May 22, 2014 01:16
-
-
Save CoderPuppy/63948360e8878f00fd86 to your computer and use it in GitHub Desktop.
Destructuring
This file contains hidden or 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
| type Identifier | |
| id::String | |
| end | |
| getter(env, id::Identifier) = env[id.id] | |
| assigner(env, id::Identifier, val) = env[id.id] = val | |
| type Access | |
| obj::Any | |
| key::Any | |
| end | |
| getter(env, access::Access) = getter(getter(env, access.obj), access.key) | |
| function assigner(env, access::Access, val) | |
| assigner(getter(env, access.obj), access.key, val) | |
| end | |
| type Number | |
| val::Integer | |
| end | |
| getter(env, num::Number) = env[num.val] | |
| getter(env, obj) = obj | |
| function assigner(env, array, val) | |
| if length(array) != length(val) | |
| error("Array's aren't the same length") | |
| end | |
| for i = 1:length(array) | |
| expr = array[i] | |
| if expr === array | |
| if length(array) == 1 | |
| error("Recursive, you probably passed in a raw value") | |
| else | |
| error("Recursive") | |
| end | |
| end | |
| assigner(env, expr, val[i]) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment