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
| class ActsAsCsv | |
| def read | |
| file = File.new(self.class.to_s.downcase + '.txt') | |
| @headers = file.gets.chomp.split(', ') | |
| file.each do |row| | |
| @result << CsvRow.new(@headers, row.chomp.split(', ')) | |
| end | |
| end |
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
| Person := Object clone | |
| Person name := "" | |
| Person introduce := method(return "Hi my name is " .. name) | |
| lucas := Person clone | |
| lucas name = "Lucas" | |
| lucas introduce |
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
| fib := method(n , | |
| if ((n == 1) or (n==2), return 1) | |
| j := 1 | |
| k := 1 | |
| for(i, 3, n, | |
| next := j + k | |
| j = k |
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
| fib := method(n, | |
| if (n <= 2, return 1, return fib(n - 1) + fib(n - 2)) | |
| ) | |
| for (i, 1, 25, fib(i) println) |
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
| Number / := method(i, if(i==0, 0, self*i**(-1))) | |
| 1/0 | |
| 1/2 | |
| 4/3 |
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
| List deepSum := method( | |
| total := 0 | |
| self foreach(i, element, (if (element type == "List", total = total + element deepSum , total = total + element))) | |
| total | |
| ) | |
| array := list(list(1,2), list(3,4), 5) | |
| array deepSum println | |
| array2 := list(list(1,list(2,3)), list(3,4), 5) |
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
| List myAverage := method( | |
| total := 0 | |
| self foreach(i, element, ( | |
| if (element type == "Number", total = total + element, Exception raise("element is not a number")) | |
| )) | |
| total / self size | |
| ) | |
| array := list(3,4,5) | |
| array myAverage println |
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
| Matrix := Object clone | |
| Matrix dim := method (x,y, | |
| if (self proto == "Object", return Matrix clone dim(x, y)) | |
| self internalList := List clone; | |
| self size_x := x; | |
| self size_y := y; | |
| for(i, 1, y, | |
| internalList append(List clone setSize(x)); | |
| ) |
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
| numberToGuess := Random value(100) round | |
| previousGuessDistance := nil | |
| 10 repeat( | |
| guess := File standardInput readLine("Enter a number between 1 and 100\n" ) asNumber(); | |
| if (guess == numberToGuess, ( | |
| "Gratz you won" println ; | |
| return | |
| ) | |
| ) |
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
| squareBrackets := method( | |
| r := List clone; | |
| call message arguments foreach(arg, | |
| r append(arg) | |
| ) | |
| ) | |
| languages := [ | |
| "Io", |
OlderNewer