Modal webapps, iterators and beyond
Excellent, easy to understand for old fashioned programmers, the introductory lecture that Sam Ruby does about continuations, Continuations for Curmudgeons.
Brian McCallister writes about guidelines to write webapps, including a reference to the concept Modal Webapps, what Stefano has been doing for years using continuations first with scheme and later with javascript.
By coincidence, I have been preparing my lesson on iterators for the University classes about the time I was reading those entries. I decided to give the students the simple example about generators that Sam gives, slightly changed to put the generator's end inside the generator itself:
def fib(max=1000):
"""Devuelve un generador para n. de Fibonacci"""
yield 0
i,j = 0,1
while j<max:
yield j
i,j = j,i+j
raise StopIteration
if __name__ == "__main__":
for n in fib():
print n
This compares very naturally with the implementation as java Iterators of the same code, except that java types get often in the way, and it is fairly more verbose:
import java.util.Iterator;
public class Fibonacci implements Iterator {
private int i=0;
private int j=1;
private int max;
public Fibonacci(int max) {
this.max = max;
}
public Fibonacci() {
this(1000);
}
public boolean hasNext() {
return j < max;
}
public Object next() {
Integer result = new Integer(j);
int temp = i;
i = j;
j = j + temp;
return result;
}
public void remove() {
throw new UnsupportedOperationException("No soportado");
}
public static void main(String[] args) {
Iterator it = new Fibonacci();
while(it.hasNext()){
System.out.println(it.next());
}
}
}
Both python generators and java iterators would allow us to write portlets in a very natural way, except that the back button would be forbidden. But it is nonetheless mostly unusable in portlets anyway, so it is not a big lose.
I'm waiting for jython to have generators (i.e, to be 2.3) to try an embedded jython interpreter to write portlets. I'm thinking that, while this comes, writing a HttpPortletRequestIterator and toying how easy it is to write portlets using it would be a win.
Map/Reduce: Map and mind twisting in programming
Abelson and Sussman, SICP: One extremely useful operation is to apply some transformation to each element in a list and generate the list of results. (...) We can abstract this general idea and capture it as a common pattern expressed as a higher-order... [more]Trackback from Santiago Gala at

This entry was published two years ago, and shortly after my server crashed, due to a power failure and spikes that Iberdrola acknowledged but denied to pay, in just the worse possible moment, before I had set up the replication in the dual cluster and when I was sick and moving. While most of my setup was preserved across the moving and my sickness, the hard disk containing those posts has remained essentially dormant until yesterday.
I used the old data to populate my mombo instance, and I think the old post is worth a rebirth here.
Posted by Santiago Gala at at