Created
January 21, 2009 15:40
-
-
Save anekos/50003 to your computer and use it in GitHub Desktop.
スコープを作る - io language
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
# スコープを作るメソッド | |
scope := method( | |
expr := call message arguments first | |
context := Object clone | |
msg := message(do) | |
msg setNext(expr) | |
context prependProto(call sender) | |
context forward := method( | |
self proto doMessage(call message clone do( setNext(nil) )) | |
) | |
context doMessage(msg) | |
) | |
obj := Object clone | |
obj l := list(1, 2, 3) | |
obj f := method( | |
scope( | |
l foreach(v, v println) | |
) | |
) | |
check := method( | |
("[obj] " .. obj slotNames join(", ")) println | |
("[v] " .. Lobby slotNames join(", ")) println | |
) | |
obj f | |
check | |
# => [obj] l, f | |
# [v] scope, obj, check, Lobby, exit, Protos, forward | |
scope( obj l foreach(v, v println) ) | |
check | |
# => [obj] l, f | |
# [v] scope, obj, check, Lobby, exit, Protos, forward | |
obj l foreach(v, v println) | |
check | |
# => [obj] l, f | |
# [v] scope, v, check, Lobby, obj, exit, Protos, forward | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment