Created
January 14, 2013 05:02
-
-
Save Javran/4527872 to your computer and use it in GitHub Desktop.
Matrix initialization, with a powerful "dim(x,y)", ref to: http://stackoverflow.com/questions/14294780/how-to-pass-a-method-but-not-activate-it-in-io-language
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
List2D := Object clone | |
List2D dim := method(x, y, | |
target := list() | |
fillStrategy := "const" | |
default := call evalArgAt(2) | |
if(default type == "Block", fillStrategy := "func") | |
for(i, 1, y, | |
subTarget := list() | |
for(j, 1, x, | |
subTarget append( | |
if(fillStrategy == "const", | |
default, | |
default call(i,j)) )) | |
target append(subTarget)) | |
target) | |
List2D dim(3,2) println | |
List2D dim(3,2,"foo") println | |
List2D dim(2,3, block(a,b, if((a+b) % 2 == 0, "foo", "bar"))) println |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the fillStrategy here is actually not necessary to be compared every time when filling elements.