Skip to content

Instantly share code, notes, and snippets.

@clairvy
Created February 3, 2010 05:56
Show Gist options
  • Select an option

  • Save clairvy/293367 to your computer and use it in GitHub Desktop.

Select an option

Save clairvy/293367 to your computer and use it in GitHub Desktop.
package {
public class Church
{
// 0
public static function zero(f : Function) : Function
{
return function (x : *) : *
{
return x;
}
}
// n + 1
public static function inc_cn(n : Function) : Function
{
return function (f : Function) : Function
{
return function (x : *) : *
{
return f(n(f)(x));
}
}
}
// m + n
public static function add_cn(m : Function, n : Function) : Function
{
return function(f : Function) : Function
{
return function (x : *) : *
{
return n(f)(m(f)(x));
}
}
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://ns.adobe.com/air/application/1.5">
<id>ChurchASCommandLineTool</id>
<filename>church</filename>
<name>church</name>
<version>v1</version>
<initialWindow>
<content>churchCUI.swf</content>
</initialWindow>
</application>
// 参考
// http://blog.s2factory.co.jp/yoshizu/2009/05/actionscript.html
package {
import flash.desktop.NativeApplication;
import flash.display.Sprite;
import flash.events.InvokeEvent;
import mx.utils.ObjectUtil;
import Church;
public class churchCUI extends Sprite
{
public function churchCUI()
{
NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, initialize);
}
private function initialize(event:InvokeEvent):void
{
var zero : Function = Church.zero; // 0
var one : Function = Church.inc_cn(zero); // 0 + 1
var two : Function = Church.inc_cn(one); // 1 + 1
var three : Function = Church.add_cn(one, two); // 1 + 2
trace("zero : " + zero (function (x : *) : * {return x + 1;})(0));
trace("one : " + one (function (x : *) : * {return x + 1;})(0));
trace("two : " + two (function (x : *) : * {return x + 1;})(0));
trace("three : " + three(function (x : *) : * {return x + 1;})(0));
NativeApplication.nativeApplication.exit();
}
}
}
BASE = churchCUI
SRC = $(BASE).as
OBJ = $(BASE).swf
ADL = adl
CNF = $(BASE)-app.xml
AIRC = amxmlc
all : build
do : build
@ $(ADL) $(CNF)
build : $(OBJ)
$(OBJ) : $(SRC)
@ $(AIRC) -output $(OBJ) $(SRC) 2>&1 | lv -Ou | cat
clean :
@ $(RM) $(RMF) $(OBJ)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment