this is not true is it?
there must be a way to make this shorter, otherways that is completely ridiculous.
""""
The equivalent code in Java, as reasonably compressed as I could make it, is:
import java.util.;
public class Fugger {
public static void main ( String[] args ) {
List numbers = new ArrayList();
for ( int i = 0; i < 5; i++ ) {
numbers.add ( new Integer(i) );
}
List squares = new ArrayList();
Iterator it = numbers.iterator();
while ( it.hasNext() ) {
int i = ((Integer)it.next()).intValue();
squares.add ( new Integer(i * i) );
}
Iterator i2 = squares.iterator();
while ( i2.hasNext() ) {
int i = ((Integer)i2.next()).intValue();
System.out.print ( i );
if ( i2.hasNext() ) {
System.out.print ( " " );
}
}
System.out.println();
}
}
""""
and his example in python:
' '.join([`x x` for x in range(1, 6)])
If you just want to print the same output, you can be ever so slightly shorter than his Perl/Python:
(dotimes (i 5) (print (expt (1+ i) 2)))
This doesn't follow his semantic steps, so it's kind of cheating, though in a real program I have a bunch of utility functions to help me out so it's about the same:
(join " " (mapcar #'sq (range 1 5)))
I think the point is not that Lisp is shorter for any given toy problem, but that Lisp allows you to build such abstractions. Even if you had join() and range() and sq() in Java, what's Java for (f x (mapcar #'g (h y z)))?
"""" The equivalent code in Java, as reasonably compressed as I could make it, is:
import java.util.;
public class Fugger { public static void main ( String[] args ) {
} """"and his example in python: ' '.join([`x x` for x in range(1, 6)])
rofl...