Skip to content

Instantly share code, notes, and snippets.

@smosher
Created April 4, 2013 05:45
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 smosher/5308105 to your computer and use it in GitHub Desktop.
Save smosher/5308105 to your computer and use it in GitHub Desktop.
http://rosettacode.org/wiki/Introspection — an Io solution exists, but makes no attempt at extra credit: Report the number of integer variables in global scope, and their sum.
// dumb test for int-ness, since Io doesn't have ints
// rather than being cheeky and doing Integer := Number clone
Number isInt := method(self == self roundDown)
countAndSumLobbyIntegers := method(
_ := Lobby slotNames select(x,
(Lobby getSlot(x) type == "Number")
) map(x, Lobby getSlot(x)) select(x, x isInt)
("There are " .. (_ size) .. " integer Numbers in Lobby") println
("Their sum is " .. (_ sum)) println
)
s := "i am a string, silly"
x := 3
y := 2.3
z := 5
countAndSumLobbyIntegers()
// Output:
// There are 2 integer Numbers in Lobby
// Their sum is 8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment