Skip to content

Instantly share code, notes, and snippets.

@rboyd
Created September 2, 2010 21:29
Show Gist options
  • Select an option

  • Save rboyd/562984 to your computer and use it in GitHub Desktop.

Select an option

Save rboyd/562984 to your computer and use it in GitHub Desktop.
v1 -- squares 1 thru 10
===
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="init(event)">
<mx:Canvas width="800" height="600">
<mx:Panel>
<mx:TextInput id="output" />
</mx:Panel>
</mx:Canvas>
<mx:Script>
<![CDATA[
private function init(event:Event):void {
var arr:Array = new Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
output.text = square_list(arr).join(', ');
}
private function sqr(elem : Number,
idx : int,
arrayNew: Array):Number {
return elem * elem;
};
public function square_list(list:Array):Array {
return list.map(sqr, list);
}
]]>
</mx:Script>
</mx:Application>
v1 -- squares 1 thru 100
===
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="init(event)">
<mx:Canvas width="800" height="600">
<mx:Panel>
<mx:TextArea id="output" width="300" height="200" />
</mx:Panel>
</mx:Canvas>
<mx:Script>
<![CDATA[
private function init(event:Event):void {
var arr:Array = new Array();
for (var i:Number = 1; i <= 100; i++) {
arr.push(i * i);
}
output.text = arr.join(', ');
}
]]>
</mx:Script>
</mx:Application>
-- dropping mxml cruft
===
private function init(event:Event):void {
var arr:Array = new Array();
for (var i:Number = 1; i <= 100; i++) {
arr.push(i * i);
}
output.text = arr.join(', ');
}
v3 -- crank it up
====
for (var i:Number = 1; i <= 1000000; i++) {
v4 -- overheat
===
cooldown.
-- psuedocode
package {
public class Calculator() {
public function square_list(List:Array):Number {
return List.map(function(Elem:Number) { return Elem * Elem; });
}
}
}
-- with type inference
package {
public class Calculator() {
public function square_list(List) {
return List.map(function(Elem) { return Elem * Elem; });
}
}
}
scala implicit types
===
object ComprehensionTest1 extends Application {
def even(from: Int, to: Int): List[Int] =
for (i <- List.range(from, to)) yield i * i
Console.println(even(0, 1000000))
}
object ComprehensionTest3 extends Application {
for (i <- Iterator.range(0, 1000000))
println("(" + i * i + ")")
}
erlang
===
[Elem * Elem || Elem <- lists:seq(1, 100)].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment