Last active
September 30, 2015 01:08
-
-
Save martintrojer/1698008 to your computer and use it in GitHub Desktop.
tail-calls
This file contains hidden or 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
IL_0000: nop | |
IL_0001: newobj instance void Program/b@12::.ctor() | |
IL_0006: ldarg.0 | |
IL_0007: ldc.i4.1 | |
IL_0008: add | |
IL_0009: tail. | |
IL_000b: call int32 Program::a(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<int32, int32="">, int32) | |
IL_0010: ret |
This file contains hidden or 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
0 getstatic #27 <app stack$b.const__0=""> | |
3 invokevirtual #54 <clojure lang="" var.getrawroot=""> | |
6 checkcast #56 <clojure ifn="" lang=""> | |
9 getstatic #31 <app stack$b.const__1=""> | |
12 invokevirtual #54 <clojure lang="" var.getrawroot=""> | |
15 aload_1 | |
16 aconst_null | |
17 astore_1 | |
18 lconst_1 | |
19 invokestatic #62 <clojure lang="" numbers.add=""> | |
22 invokeinterface #65 <clojure ifn.invoke="" lang=""> count 3 | |
27 areturn |
This file contains hidden or 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
bool inA = true; | |
while (true) { | |
if (inA) { | |
// do A stuff | |
inA = false; | |
} | |
else { | |
// do B stuff | |
inA = true; | |
} | |
} |
This file contains hidden or 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
let a (f:int->int) n = | |
f (n + 1) | |
let rec b n = | |
a b (n + 1) |
This file contains hidden or 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
(defn sum3[k n] | |
(if | |
(= n 0) (k 0) | |
(sum3 (fn [m] (k (+ n m))) (dec n)))) | |
(sum3 identity 10) |
This file contains hidden or 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
def sumImperative(n:Int):Int = { | |
var res = 0 | |
for (i <- n to(0, -1)) { | |
res = res + i | |
} | |
res | |
} |
This file contains hidden or 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
public static int sum(int acc, int n) { | |
while (n != 0) { | |
int arg_12_0 = n + acc; | |
n--; | |
acc = arg_12_0; | |
} | |
} |
This file contains hidden or 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
public int sum2(int acc, int n) { | |
while (true) { | |
if (n == 0) | |
return acc; | |
n -= 1; acc = n + acc; | |
} | |
} |
This file contains hidden or 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
(defn sum2[acc n] | |
(if | |
(= n 0) acc | |
(recur (+ n acc) (dec n)))) |
This file contains hidden or 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
def sum2(acc:Int, n:Int):Int = { | |
if (n==0) acc | |
else sum2((n+acc),(n-1)) | |
} |
This file contains hidden or 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
let rec sum n = | |
if n = 0 then 0 | |
else n + sum(n-1) |
This file contains hidden or 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
(defn a[f n] | |
#(f (inc n))) | |
(defn b[n] | |
#(a b (inc n))) | |
(trampoline b 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment