Skip to content

Instantly share code, notes, and snippets.

@anekos
Created January 21, 2009 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anekos/50003 to your computer and use it in GitHub Desktop.
Save anekos/50003 to your computer and use it in GitHub Desktop.
スコープを作る - io language
# スコープを作るメソッド
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