[plt-scheme] Functional Abstraction in Java

From: Andrei Estioco (chadestioco at gmail.com)
Date: Wed Jul 1 13:23:13 EDT 2009

Hello. My apologies if I am asking this in the wrong mailing list (this
being a Java question). But since I encountered this concept in HtDP, I
thought of asking around here. (See Chapter 21 of HtDP). See I have a
function private int getSaturdays(int x, int fordays){ int Weeks =
getWeeks(x, fordays); int SaturdayCounter = 0; int i = 1; while(i <=
hartalWeeks){ if(getSaturdayIndex(i) % x == 0){ SaturdayCounter++; i++; }
else{ i++; } } return SaturdayCounter; } and another one private int
getSundays(int x, int fordays){ int Weeks = getWeeks(x, fordays); int
SundaysCounter = 0; int i = 1; while(i <= hartalWeeks){ if(getSundayIndex(i)
% x == 0){ SundayCounter++; i++; } else{ i++; } } return SundayCounter; } As
obvious, they do the same process, their sole difference being a function
call (the one in the if line). Now, if I were to do this in Scheme, I'll
just add another argument to my function which will be called in the if line
(as in Chapter 21). However, I do not know how to do this in Java.
I know how to sort in Java using the Comparator interface and all that OO
stuff. I thought of using that style here but then I was wondering if I
could do this without OO. Is it possible?

Thanks in advance,
Chad Estioco
BS Computer Science (ongoing)
University of the Philippines-Diliman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20090702/1a71c6e5/attachment.html>

Posted on the users mailing list.