Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>2D Picking with SVG</title> | |
<meta name="description" content=""> | |
<meta name="author" content="Yannick Assogba"> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/stats.js/r14/Stats.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.5/dat.gui.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script> |
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
#fib with memoization | |
fakeClosure := Object clone | |
fakeClosure memo := Map clone | |
fakeClosure fibmemo := method(num, | |
#I need this next line when i assign this method to a slot in the | |
#outer object (see last line of this gist). | |
#Feels like a 'this/self' binding issue. Otherwise i would have expected | |
#the memo slot on fakeClosure to be visible here | |
memo := fakeClosure memo #not strictly necessary when calling 'fakeClosure fibmemo' | |
memo atPut(0 asString, 0) |
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
#traditional recursive fib | |
fib := method(num, | |
if(num == 0 or num == 1 | |
, num | |
, fib(num-1) + fib(num-2) | |
) | |
) |
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
#differential inheritance | |
#making types (objects with a type field) | |
Shape := Object clone | |
Shape area := method(width * height) | |
Shape width := 5 | |
Shape height := 9 | |
Rect := Shape clone | |
Square := Shape clone | |
Ellipse := Shape clone |
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
fakeClosure := Object clone do( | |
memo := Map clone | |
fibmemo := block(num, #note 'blocks' are lexically scoped | |
memo atPut(0 asString, 0) | |
memo atPut(1 asString, 1) | |
fibhelp := method(num, | |
one := memo at((num-1) asString) | |
two := memo at((num-2) asString) | |
if(one == nil | |
, one = fibhelp(num-1,memo) |
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
#get rid of the object and just use a method as a container | |
fibmemoclosure := method(num, | |
memo := Map clone | |
fibmemo := block(num, #note 'blocks' are lexically scoped | |
memo atPut(0 asString, 0) | |
memo atPut(1 asString, 1) | |
fibhelp := method(num, | |
one := memo at((num-1) asString) | |
two := memo at((num-2) asString) | |
if(one == nil |
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
#Minimal mixins in Io! | |
Object mix := method(obj, | |
#grab all the objects methods and add them to the target | |
#the target is the object mixing in the mixin | |
mixer := call target | |
obj slotNames foreach(slotName, | |
if(obj getSlot(slotName) type == "Block" | |
, mixer setSlot(slotName, obj getSlot(slotName)) | |
#ignore properties for the moment | |
) |
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
#Actors | |
#this code is from day 2 | |
Delay := Object clone | |
Delay send := method( | |
args := call message arguments | |
for(i,0, args size - 1, 2, | |
delay := doMessage(args at(i)) | |
msg := args at(i+1) | |
wait(delay) |
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
#The sleeping barber problem http://en.wikipedia.org/wiki/Sleeping_barber_problem | |
#Solved with Io actors | |
Barber := Object clone do( | |
sleeping := false | |
wakeup := method( | |
"Waking Up!" println | |
sleeping = false | |
) |
OlderNewer