Extract from Jigsaw
-
This is an extract from the 'Implementing Programming Languages using C# 4.0' article published last week (late oct 2011) Some of the code really blow my mind. This code works, but how on earth does it work? I need to spend spend some time on this.
public delegate Lambda Lambda(Lambda x); public static Lambda Id = x => x; public static Lambda Zero = f => x => x; public static Lambda True = x => y => x; public static Lambda False = x => y => y; public static Lambda One = f => x => f(x); public static Lambda Two = f => x => f(f(x)); public static Lambda Succ = n => f => x => f(n(f)(x)); public static Lambda Three = Succ(Two); public static Lambda Pred = n => f => x => n(g => h => h(g(f)))(u => x)(Id); public static Lambda Plus = m => n => f => x => m(f)(n(f)(x)); public static Lambda Sub = m => n => n (Pred) (m); public static Lambda And = p => q => p(q)(p); public static Lambda Or = p => q => p(p)(q); public static Lambda Not = p => a => b => p(b)(a); public static Lambda IfThenElse = p => a => b => p(a)(b); public static Lambda IsZero = n => n(x => False)(True); public static Lambda IsLtEqOne = n => IsZero(Pred(n)); public static Lambda Pair = x => y => f => f(x)(y); public static Lambda First = pair => pair(True); public static Lambda Second = pair => pair(False); public static Lambda Nil = x => True; public static Lambda Null = p => p(x => y => False); public static Lambda LtEq = x => y => IsZero(Sub(x)(y)); public static Lambda Gt = x => y => LtEq(y)(x); public static Lambda Eq = x => y => And(LtEq(x)(y))(LtEq(y)(x));
-
This is an extract from the 'Implementing Programming Languages using C# 4.0' article published last week (late oct 2011) Some of the code really blow my mind. This code works, but how on earth does it work? I need to spend spend some time on this.
public delegate Lambda Lambda(Lambda x); public static Lambda Id = x => x; public static Lambda Zero = f => x => x; public static Lambda True = x => y => x; public static Lambda False = x => y => y; public static Lambda One = f => x => f(x); public static Lambda Two = f => x => f(f(x)); public static Lambda Succ = n => f => x => f(n(f)(x)); public static Lambda Three = Succ(Two); public static Lambda Pred = n => f => x => n(g => h => h(g(f)))(u => x)(Id); public static Lambda Plus = m => n => f => x => m(f)(n(f)(x)); public static Lambda Sub = m => n => n (Pred) (m); public static Lambda And = p => q => p(q)(p); public static Lambda Or = p => q => p(p)(q); public static Lambda Not = p => a => b => p(b)(a); public static Lambda IfThenElse = p => a => b => p(a)(b); public static Lambda IsZero = n => n(x => False)(True); public static Lambda IsLtEqOne = n => IsZero(Pred(n)); public static Lambda Pair = x => y => f => f(x)(y); public static Lambda First = pair => pair(True); public static Lambda Second = pair => pair(False); public static Lambda Nil = x => True; public static Lambda Null = p => p(x => y => False); public static Lambda LtEq = x => y => IsZero(Sub(x)(y)); public static Lambda Gt = x => y => LtEq(y)(x); public static Lambda Eq = x => y => And(LtEq(x)(y))(LtEq(y)(x));
-
This is an extract from the 'Implementing Programming Languages using C# 4.0' article published last week (late oct 2011) Some of the code really blow my mind. This code works, but how on earth does it work? I need to spend spend some time on this.
public delegate Lambda Lambda(Lambda x); public static Lambda Id = x => x; public static Lambda Zero = f => x => x; public static Lambda True = x => y => x; public static Lambda False = x => y => y; public static Lambda One = f => x => f(x); public static Lambda Two = f => x => f(f(x)); public static Lambda Succ = n => f => x => f(n(f)(x)); public static Lambda Three = Succ(Two); public static Lambda Pred = n => f => x => n(g => h => h(g(f)))(u => x)(Id); public static Lambda Plus = m => n => f => x => m(f)(n(f)(x)); public static Lambda Sub = m => n => n (Pred) (m); public static Lambda And = p => q => p(q)(p); public static Lambda Or = p => q => p(p)(q); public static Lambda Not = p => a => b => p(b)(a); public static Lambda IfThenElse = p => a => b => p(a)(b); public static Lambda IsZero = n => n(x => False)(True); public static Lambda IsLtEqOne = n => IsZero(Pred(n)); public static Lambda Pair = x => y => f => f(x)(y); public static Lambda First = pair => pair(True); public static Lambda Second = pair => pair(False); public static Lambda Nil = x => True; public static Lambda Null = p => p(x => y => False); public static Lambda LtEq = x => y => IsZero(Sub(x)(y)); public static Lambda Gt = x => y => LtEq(y)(x); public static Lambda Eq = x => y => And(LtEq(x)(y))(LtEq(y)(x));
-
This is an extract from the 'Implementing Programming Languages using C# 4.0' article published last week (late oct 2011) Some of the code really blow my mind. This code works, but how on earth does it work? I need to spend spend some time on this.
public delegate Lambda Lambda(Lambda x); public static Lambda Id = x => x; public static Lambda Zero = f => x => x; public static Lambda True = x => y => x; public static Lambda False = x => y => y; public static Lambda One = f => x => f(x); public static Lambda Two = f => x => f(f(x)); public static Lambda Succ = n => f => x => f(n(f)(x)); public static Lambda Three = Succ(Two); public static Lambda Pred = n => f => x => n(g => h => h(g(f)))(u => x)(Id); public static Lambda Plus = m => n => f => x => m(f)(n(f)(x)); public static Lambda Sub = m => n => n (Pred) (m); public static Lambda And = p => q => p(q)(p); public static Lambda Or = p => q => p(p)(q); public static Lambda Not = p => a => b => p(b)(a); public static Lambda IfThenElse = p => a => b => p(a)(b); public static Lambda IsZero = n => n(x => False)(True); public static Lambda IsLtEqOne = n => IsZero(Pred(n)); public static Lambda Pair = x => y => f => f(x)(y); public static Lambda First = pair => pair(True); public static Lambda Second = pair => pair(False); public static Lambda Nil = x => True; public static Lambda Null = p => p(x => y => False); public static Lambda LtEq = x => y => IsZero(Sub(x)(y)); public static Lambda Gt = x => y => LtEq(y)(x); public static Lambda Eq = x => y => And(LtEq(x)(y))(LtEq(y)(x));
-
This is an extract from the 'Implementing Programming Languages using C# 4.0' article published last week (late oct 2011) Some of the code really blow my mind. This code works, but how on earth does it work? I need to spend spend some time on this.
public delegate Lambda Lambda(Lambda x); public static Lambda Id = x => x; public static Lambda Zero = f => x => x; public static Lambda True = x => y => x; public static Lambda False = x => y => y; public static Lambda One = f => x => f(x); public static Lambda Two = f => x => f(f(x)); public static Lambda Succ = n => f => x => f(n(f)(x)); public static Lambda Three = Succ(Two); public static Lambda Pred = n => f => x => n(g => h => h(g(f)))(u => x)(Id); public static Lambda Plus = m => n => f => x => m(f)(n(f)(x)); public static Lambda Sub = m => n => n (Pred) (m); public static Lambda And = p => q => p(q)(p); public static Lambda Or = p => q => p(p)(q); public static Lambda Not = p => a => b => p(b)(a); public static Lambda IfThenElse = p => a => b => p(a)(b); public static Lambda IsZero = n => n(x => False)(True); public static Lambda IsLtEqOne = n => IsZero(Pred(n)); public static Lambda Pair = x => y => f => f(x)(y); public static Lambda First = pair => pair(True); public static Lambda Second = pair => pair(False); public static Lambda Nil = x => True; public static Lambda Null = p => p(x => y => False); public static Lambda LtEq = x => y => IsZero(Sub(x)(y)); public static Lambda Gt = x => y => LtEq(y)(x); public static Lambda Eq = x => y => And(LtEq(x)(y))(LtEq(y)(x));
Pascal Ganaye wrote:
public delegate Lambda Lambda(Lambda x);
Would be cooler if it was written as:
delegate λ λ(λ x);
Which is perfectly legal in C# :)
-
This is an extract from the 'Implementing Programming Languages using C# 4.0' article published last week (late oct 2011) Some of the code really blow my mind. This code works, but how on earth does it work? I need to spend spend some time on this.
public delegate Lambda Lambda(Lambda x); public static Lambda Id = x => x; public static Lambda Zero = f => x => x; public static Lambda True = x => y => x; public static Lambda False = x => y => y; public static Lambda One = f => x => f(x); public static Lambda Two = f => x => f(f(x)); public static Lambda Succ = n => f => x => f(n(f)(x)); public static Lambda Three = Succ(Two); public static Lambda Pred = n => f => x => n(g => h => h(g(f)))(u => x)(Id); public static Lambda Plus = m => n => f => x => m(f)(n(f)(x)); public static Lambda Sub = m => n => n (Pred) (m); public static Lambda And = p => q => p(q)(p); public static Lambda Or = p => q => p(p)(q); public static Lambda Not = p => a => b => p(b)(a); public static Lambda IfThenElse = p => a => b => p(a)(b); public static Lambda IsZero = n => n(x => False)(True); public static Lambda IsLtEqOne = n => IsZero(Pred(n)); public static Lambda Pair = x => y => f => f(x)(y); public static Lambda First = pair => pair(True); public static Lambda Second = pair => pair(False); public static Lambda Nil = x => True; public static Lambda Null = p => p(x => y => False); public static Lambda LtEq = x => y => IsZero(Sub(x)(y)); public static Lambda Gt = x => y => LtEq(y)(x); public static Lambda Eq = x => y => And(LtEq(x)(y))(LtEq(y)(x));
When i try to read through this my brain starts to reboot. I think i first have to upload a new instructionset before trying to do this again. on the side; the nice thing of it is that the app won't process it untill the result is needed. So far for the "it compiles therefore it works"
Cogito ergo sum
-
This is an extract from the 'Implementing Programming Languages using C# 4.0' article published last week (late oct 2011) Some of the code really blow my mind. This code works, but how on earth does it work? I need to spend spend some time on this.
public delegate Lambda Lambda(Lambda x); public static Lambda Id = x => x; public static Lambda Zero = f => x => x; public static Lambda True = x => y => x; public static Lambda False = x => y => y; public static Lambda One = f => x => f(x); public static Lambda Two = f => x => f(f(x)); public static Lambda Succ = n => f => x => f(n(f)(x)); public static Lambda Three = Succ(Two); public static Lambda Pred = n => f => x => n(g => h => h(g(f)))(u => x)(Id); public static Lambda Plus = m => n => f => x => m(f)(n(f)(x)); public static Lambda Sub = m => n => n (Pred) (m); public static Lambda And = p => q => p(q)(p); public static Lambda Or = p => q => p(p)(q); public static Lambda Not = p => a => b => p(b)(a); public static Lambda IfThenElse = p => a => b => p(a)(b); public static Lambda IsZero = n => n(x => False)(True); public static Lambda IsLtEqOne = n => IsZero(Pred(n)); public static Lambda Pair = x => y => f => f(x)(y); public static Lambda First = pair => pair(True); public static Lambda Second = pair => pair(False); public static Lambda Nil = x => True; public static Lambda Null = p => p(x => y => False); public static Lambda LtEq = x => y => IsZero(Sub(x)(y)); public static Lambda Gt = x => y => LtEq(y)(x); public static Lambda Eq = x => y => And(LtEq(x)(y))(LtEq(y)(x));
-
This is an extract from the 'Implementing Programming Languages using C# 4.0' article published last week (late oct 2011) Some of the code really blow my mind. This code works, but how on earth does it work? I need to spend spend some time on this.
public delegate Lambda Lambda(Lambda x); public static Lambda Id = x => x; public static Lambda Zero = f => x => x; public static Lambda True = x => y => x; public static Lambda False = x => y => y; public static Lambda One = f => x => f(x); public static Lambda Two = f => x => f(f(x)); public static Lambda Succ = n => f => x => f(n(f)(x)); public static Lambda Three = Succ(Two); public static Lambda Pred = n => f => x => n(g => h => h(g(f)))(u => x)(Id); public static Lambda Plus = m => n => f => x => m(f)(n(f)(x)); public static Lambda Sub = m => n => n (Pred) (m); public static Lambda And = p => q => p(q)(p); public static Lambda Or = p => q => p(p)(q); public static Lambda Not = p => a => b => p(b)(a); public static Lambda IfThenElse = p => a => b => p(a)(b); public static Lambda IsZero = n => n(x => False)(True); public static Lambda IsLtEqOne = n => IsZero(Pred(n)); public static Lambda Pair = x => y => f => f(x)(y); public static Lambda First = pair => pair(True); public static Lambda Second = pair => pair(False); public static Lambda Nil = x => True; public static Lambda Null = p => p(x => y => False); public static Lambda LtEq = x => y => IsZero(Sub(x)(y)); public static Lambda Gt = x => y => LtEq(y)(x); public static Lambda Eq = x => y => And(LtEq(x)(y))(LtEq(y)(x));
-
This is an extract from the 'Implementing Programming Languages using C# 4.0' article published last week (late oct 2011) Some of the code really blow my mind. This code works, but how on earth does it work? I need to spend spend some time on this.
public delegate Lambda Lambda(Lambda x); public static Lambda Id = x => x; public static Lambda Zero = f => x => x; public static Lambda True = x => y => x; public static Lambda False = x => y => y; public static Lambda One = f => x => f(x); public static Lambda Two = f => x => f(f(x)); public static Lambda Succ = n => f => x => f(n(f)(x)); public static Lambda Three = Succ(Two); public static Lambda Pred = n => f => x => n(g => h => h(g(f)))(u => x)(Id); public static Lambda Plus = m => n => f => x => m(f)(n(f)(x)); public static Lambda Sub = m => n => n (Pred) (m); public static Lambda And = p => q => p(q)(p); public static Lambda Or = p => q => p(p)(q); public static Lambda Not = p => a => b => p(b)(a); public static Lambda IfThenElse = p => a => b => p(a)(b); public static Lambda IsZero = n => n(x => False)(True); public static Lambda IsLtEqOne = n => IsZero(Pred(n)); public static Lambda Pair = x => y => f => f(x)(y); public static Lambda First = pair => pair(True); public static Lambda Second = pair => pair(False); public static Lambda Nil = x => True; public static Lambda Null = p => p(x => y => False); public static Lambda LtEq = x => y => IsZero(Sub(x)(y)); public static Lambda Gt = x => y => LtEq(y)(x); public static Lambda Eq = x => y => And(LtEq(x)(y))(LtEq(y)(x));
Pascal Ganaye wrote:
This code works, but how on earth does it work?
There are many ways to create code that "works". From that set there are a limited number which are easily maintainable. Myself I prefer to create code that works and which is easily maintainable. It takes time to do that just as it takes time to create 'clever' code. However the former is something that actually has something to do with what I get paid for where the latter does not.
-
Pascal Ganaye wrote:
but how on earth does it work?
I think there was a liberal sprinkling of pixie dust applied. :omg:
Dave Find Me On: Web|Facebook|Twitter|LinkedIn
Folding Stats: Team CodeProject
I think there was a liberal amount of pixie dust snorted.
-
Pascal Ganaye wrote:
This code works, but how on earth does it work?
There are many ways to create code that "works". From that set there are a limited number which are easily maintainable. Myself I prefer to create code that works and which is easily maintainable. It takes time to do that just as it takes time to create 'clever' code. However the former is something that actually has something to do with what I get paid for where the latter does not.
-
This is an extract from the 'Implementing Programming Languages using C# 4.0' article published last week (late oct 2011) Some of the code really blow my mind. This code works, but how on earth does it work? I need to spend spend some time on this.
public delegate Lambda Lambda(Lambda x); public static Lambda Id = x => x; public static Lambda Zero = f => x => x; public static Lambda True = x => y => x; public static Lambda False = x => y => y; public static Lambda One = f => x => f(x); public static Lambda Two = f => x => f(f(x)); public static Lambda Succ = n => f => x => f(n(f)(x)); public static Lambda Three = Succ(Two); public static Lambda Pred = n => f => x => n(g => h => h(g(f)))(u => x)(Id); public static Lambda Plus = m => n => f => x => m(f)(n(f)(x)); public static Lambda Sub = m => n => n (Pred) (m); public static Lambda And = p => q => p(q)(p); public static Lambda Or = p => q => p(p)(q); public static Lambda Not = p => a => b => p(b)(a); public static Lambda IfThenElse = p => a => b => p(a)(b); public static Lambda IsZero = n => n(x => False)(True); public static Lambda IsLtEqOne = n => IsZero(Pred(n)); public static Lambda Pair = x => y => f => f(x)(y); public static Lambda First = pair => pair(True); public static Lambda Second = pair => pair(False); public static Lambda Nil = x => True; public static Lambda Null = p => p(x => y => False); public static Lambda LtEq = x => y => IsZero(Sub(x)(y)); public static Lambda Gt = x => y => LtEq(y)(x); public static Lambda Eq = x => y => And(LtEq(x)(y))(LtEq(y)(x));
Looks like mutton dressed as... no, no, I'm not going to finish that. Nice snippet. Little workout for the neurons.
Smokie, this is not 'Nam. This is bowling. There are rules. http://melpadden.wordpress.com LinkedIn
-
This is an extract from the 'Implementing Programming Languages using C# 4.0' article published last week (late oct 2011) Some of the code really blow my mind. This code works, but how on earth does it work? I need to spend spend some time on this.
public delegate Lambda Lambda(Lambda x); public static Lambda Id = x => x; public static Lambda Zero = f => x => x; public static Lambda True = x => y => x; public static Lambda False = x => y => y; public static Lambda One = f => x => f(x); public static Lambda Two = f => x => f(f(x)); public static Lambda Succ = n => f => x => f(n(f)(x)); public static Lambda Three = Succ(Two); public static Lambda Pred = n => f => x => n(g => h => h(g(f)))(u => x)(Id); public static Lambda Plus = m => n => f => x => m(f)(n(f)(x)); public static Lambda Sub = m => n => n (Pred) (m); public static Lambda And = p => q => p(q)(p); public static Lambda Or = p => q => p(p)(q); public static Lambda Not = p => a => b => p(b)(a); public static Lambda IfThenElse = p => a => b => p(a)(b); public static Lambda IsZero = n => n(x => False)(True); public static Lambda IsLtEqOne = n => IsZero(Pred(n)); public static Lambda Pair = x => y => f => f(x)(y); public static Lambda First = pair => pair(True); public static Lambda Second = pair => pair(False); public static Lambda Nil = x => True; public static Lambda Null = p => p(x => y => False); public static Lambda LtEq = x => y => IsZero(Sub(x)(y)); public static Lambda Gt = x => y => LtEq(y)(x); public static Lambda Eq = x => y => And(LtEq(x)(y))(LtEq(y)(x));
Please complete the following analogy: RegEx is to text-processing ... as C# Lambda is to ____________ ? thanks, Bill
Scipio: "That's true, Berganza; and what makes the miracle greater is, that we not only speak, but hold intelligent discourse, as though we had souls capable of reason; whereas we are so far from having it, that the difference between brutes and man consists in this, that man is a rational animal, and the brute is irrational." Cervantes, "Colloquy of Dogs," 1613CE. The two talking dogs, Scipio, Berganza, are hallucinations in the mind of a soldier with plague fever undergoing a "sweating" cure.
-
Pascal Ganaye wrote:
public delegate Lambda Lambda(Lambda x);
Would be cooler if it was written as:
delegate λ λ(λ x);
Which is perfectly legal in C# :)
-
I can't tell you. My lame DELL laptop does not have a numpad and numpad emulation... Try one of these methods: http://www.fileformat.info/tip/microsoft/enter_unicode.htm[^] Or the ugly version
\u03bb
-
I can't tell you. My lame DELL laptop does not have a numpad and numpad emulation... Try one of these methods: http://www.fileformat.info/tip/microsoft/enter_unicode.htm[^] Or the ugly version
\u03bb
Has everyone forgotten
charmap
?Software Zen:
delete this;
-
This is an extract from the 'Implementing Programming Languages using C# 4.0' article published last week (late oct 2011) Some of the code really blow my mind. This code works, but how on earth does it work? I need to spend spend some time on this.
public delegate Lambda Lambda(Lambda x); public static Lambda Id = x => x; public static Lambda Zero = f => x => x; public static Lambda True = x => y => x; public static Lambda False = x => y => y; public static Lambda One = f => x => f(x); public static Lambda Two = f => x => f(f(x)); public static Lambda Succ = n => f => x => f(n(f)(x)); public static Lambda Three = Succ(Two); public static Lambda Pred = n => f => x => n(g => h => h(g(f)))(u => x)(Id); public static Lambda Plus = m => n => f => x => m(f)(n(f)(x)); public static Lambda Sub = m => n => n (Pred) (m); public static Lambda And = p => q => p(q)(p); public static Lambda Or = p => q => p(p)(q); public static Lambda Not = p => a => b => p(b)(a); public static Lambda IfThenElse = p => a => b => p(a)(b); public static Lambda IsZero = n => n(x => False)(True); public static Lambda IsLtEqOne = n => IsZero(Pred(n)); public static Lambda Pair = x => y => f => f(x)(y); public static Lambda First = pair => pair(True); public static Lambda Second = pair => pair(False); public static Lambda Nil = x => True; public static Lambda Null = p => p(x => y => False); public static Lambda LtEq = x => y => IsZero(Sub(x)(y)); public static Lambda Gt = x => y => LtEq(y)(x); public static Lambda Eq = x => y => And(LtEq(x)(y))(LtEq(y)(x));