Created
April 4, 2013 05:45
-
-
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.
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
// 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