This amuses me greatly. Thanks to chromatic on the modern perl blog for the link.
This amuses me greatly. Thanks to chromatic on the modern perl blog for the link.
I recently read a blog post by Alex Miller about Clojure multi-methods.
It described and answered a question his friend had asked him, as well as discussing some related problems. I'm going to showcase the different options Perl 6 provides for solving these same problems. Here's the initial question:
Is it possible to write a multimethod that has defmethods which handle ranges of values? For example, say that a person has an age. Can I write a multimethod that accepts a person as a parameter and returns "child" if age < 16, "adult" if 16 <= age < 66 and "senior" if age >= 66?As in Clojure, the answer is "Sure." In keeping with TIMTOWDI, Perl 6 provides several ways to do this.
This post does a rather good job of covering some of the new features in Perl 6 in a very readable way.
As you've probably heard by now, Oracle has decided to file suit against Google, claiming multiple counts of infringement against Java or JVM patents and copyrights they acquired when they assimilated Sun Microsystems this past year. Since I'm unlikely to keep my mouth shut about even trivial matters, something this big obviously requires at least a couple thousand words.
It's long, but he has some interesting thoughts and a decent amount of background that I wasn't necessarily aware of. It's nice that he lists all of the patents, too.
This function decorates a function with tail call optimization. It does this by throwing an exception if it is it's own grandparent, and catching such exceptions to fake the tail call optimization.
Sometimes I wonder why a whole bunch of Scheme loving folks use Python. Then, I see rather clever things like this, and it starts to make more sense. I do wonder how much of a performance penalty something like this incurs, though.
The following code does not compile:
public class A { public static void main(String[] args) { int i = Integer.parseInt(args[0]); switch (i) { case X: System.out.println("ONE!"); break; case Y: System.out.println("TWO!"); break; default: System.out.println("ZERO!"); break; } } public static final int X = B.getNumber("X"); public static final int Y = B.getNumber("Y");}class B { public static int getNumber(String s) { if (s.equals("X")) { return 1; } else if (s.equals("Y")) { return 2; } else { return 0; } }}
The compile error is:
A.java:5: constant expression required case X: System.out.println("ONE!"); break; ^A.java:6: constant expression required case Y: System.out.println("TWO!"); break; ^2 errors
I think I'll leave explaining why as an exercise for the reader. (Or for a future post. ;-)
Potion is an object- and mixin-oriented (traits) language.
_why's been working on a new top secret project. Wish I had more time to play with all the neat languages out there. This one seems to have a lot of neat ideas.
Rawr, a packaging and deployment tool, is all you'll ever need for your JRuby projects. With Rawr, a simple, pre-generated configuration file turns your code into an executable jar, a .exe for Windows, and a .app for OS X.
It's kinda like Shoes in that it gives you an exe for Windows, an app for OS X, and a jar that you can use everywhere else. Cool stuff.
I probably start up a JVM a thousand times a day. Test runs, benchmark runs, bug confirmation, API exploration, or running actual apps. And in many of these runs, I use various JVM switches to tweak performance or investigate runtime metrics. Here's a short list of my favorite JVM switches (note these are Hotspot/OpenJDK/SunJDK switches, and may or may not work on yours. Apple JVM is basically the same, so these work).
If you write any serious Java at all, I highly recommend that you click the link above and read his post. It is full of many amazing gems that I can see being really useful for optimizing and debugging Java applications.