User loginNavigation 
Can local variables assignments be considered pure functional without monads?Okay, this might seem like an odd question, but is there contention on whether or not a while loop that performs assignment on local function variables is pure functional? For example the following Java code: int process(int[] xs) { int zeros = 0; int sum = 0; int i=0; while (i < xs.Size) { if (xs[i] == 0) zeros++; sum += xs[i]; ++i; } return sum  zeros; } Now I have heard frequently that the above code is considered to have sideeffects because of the local assignments to variables. However, the mapping to purefunctional stackbased code (here shown in Cat) is very straightforward: define process { // top argument = xs 0 // zeros 0 // sum 0 // i [ dig3 // bring xs to top of local stack dupd swap get_at eqz // xs[i] == 0 [[inc] dip3] // inc zeros [] if dupd swap get_at // tmp = xs[i] [bury3] dip // put xs to bottom of local stack swap [add_int] dip // sum += tmp inc // ++i ] [ dig3 count [bury3] dip // tmp = xs.Size dupd lt_int // i < tmp ] while pop // remove i swap sub_int // sumzeros } So, my problem is that I am not sure whether this is old news or new news. Any feedback would be appreciated. By cdiggins at 20080410 17:30  LtU Forum  previous forum topic  next forum topic  other blogs  9875 reads

Browse archivesActive forum topicsNew forum topics 
Recent comments
1 week 3 days ago
1 week 5 days ago
1 week 6 days ago
1 week 6 days ago
2 weeks 2 hours ago
2 weeks 18 hours ago
2 weeks 23 hours ago
2 weeks 1 day ago
2 weeks 1 day ago
2 weeks 1 day ago