Tuesday, November 17, 2009

(attempt grasp this weird stuff)

ב''ה


Thank you for visiting my blog. This blog is to attempt to grasp and explain functional programing and other cool programing things.


My latest attempt at understanding this stuff was going through this article:




http://www.defmacro.org/ramblings/fp.html


The pseudo-code recursive function was too hard to understand so I wrote out what each function call would come back as.

String reverse(String arg) {
    if(arg.length == 0) {
        return arg;
    }
    else {
        return reverse(arg.substring(1, arg.length)) + arg.substring(0, 1);
    }
}


If you would pass in the string "string" this is what would happen:


What would be passed in on each recursive call:

string -length 6
tring + s - length 5
ring + t - length 4
ing + r - length 3
ng + i - length 2
g + n - length 1
'' + g - length 0


In order, what would be returned:
return g
return gn
return gni
return gnir
return gnirt
return gnirts

No comments:

Post a Comment