Hudson Moved to Denmark

I just migrated our Hudson continuous integration server from my workstation (finland.cs, now a Dell Studio 435 with a 2.66 GHz i7 — thanks Corky!) to denmark.cs, a dedicated server (my former workstation, a Dell Dimension 9200 with a 3 GHz Pentium 4).

The builds now take a bit longer again (currently about 10 minutes instead of less than 5 minutes for the DrJava unit tests), but I can run the builds without draining CPU time from my workstation. Occasionally, finland.cs became difficult to use when the jobs were running. I scheduled the builds for off-peak times when I’m less likely to be at the office (midnight, 6 AM and 6 PM, and weekends), but the change-triggered builds could run at any time.

There are still a few issues: For some reason, the web server isn’t accessible yet from denmark.cs, so automatic Javadoc, Clover, FindBugs and documentation updates fail. The weekly jar job doesn’t work either.

There is also a bug (issues #4586 and #4596) in Hudson that prevents me from properly configuring the email notifications (although they do seem to work already, as the web server failures mentioned above suggest).

All of this should be resolved pretty soon, though. The web server issue is probably trivial (although I don’t know what to do), and new builds of Hudson are released almost every week, and Kohsuke Kawaguchi has already indicated that this will be fixed in the next version, 1.328.

Share
Posted in DrJava, Uncategorized | Leave a comment

Print This Post Print This Post  

All in One File!

After integrating Mint into DrJava last week, we have now made it even simpler to experiment with Mint: You can download a copy of DrJava that already includes the Mint compiler, all in one file:

That means on Windows and Linux, provided you have installed the JDK 6, you can just double-click on the jar file or start it using

java -jar drjava-r5104-mint-r14185.jar

On MacOS, you still need to install Soylatte and X11 as described in the previous post, but you don’t need to set up Mint. Just run it with

java -jar drjava-r5104-mint-r14185.jar

using Soylatte under X11.

This DrJava with Mint jar file doesn’t give you the mintc and mint command line utilities, but you can edit, compile and run Mint programs in DrJava. This is probably the easiest way to experiment with Mint!

Note: We recommend that you disable DrJava’s auto-update feature when using the DrJava with Mint jar file. The auto-update would otherwise download new versions of DrJava without integrated Mint. Please go to Edit -> Preferences, select the Notifications category, and set “Check for new versions?” to “none (disabled)”.

(Re-posted from The Java Mint Blog)

Share
Posted in DrJava, Mint | Leave a comment

Print This Post Print This Post  

Short DrJava Review on SourceForge

Someone wrote on SourceForge about DrJava:

This program is excellent for its’ intended use. Best part is that you can put it on a memory stick and run it.

Thanks! I concur.

Share
Posted in DrJava | Leave a comment

Print This Post Print This Post  

DrJava with Mint Released

The latest releases of DrJava contains a compiler adapter for Mint. That means it is possible to conveniently compile Mint programs in the DrJava IDE.

To experiment with Mint and DrJava, please do the following:

  1. Download DrJava with Mint the JavaMint implementation page. The file will be named drjava-rxxxx-mint-ryyyyy.jar, where xxxx indicates the version of DrJava and yyyyy the version of Java Mint.
  2. MacOS only: Java Mint requires Java 6. If you have a 32-bit Mac for which Apple does not offer Java 6, you can use Soylatte, but that means DrJava needs to be run under Soylatte as well. Soylatte requires X11 to display graphical user interfaces (GUIs).
  1. Change your PATH environment variable so that Soylatte’s java and javac commands are found first. Edit your .bash_profile or .bashrc file and add the following line at the end of the file:
    export PATH=/usr/local/soylatte/bin:$PATH
  2. Install Apple’s X11. You can find it on your MacOS X installation DVD (preferred!). Here are also some links where you may download X11 (not checked by us — if you try any of these, please let us know!):
  1. Start the X11 application. A terminal window should open. Put the cursor in that terminal window — you will start DrJava from there.
  1. Start DrJava using
    java -jar drjava-rxxxx-mint-ryyyyy.jar

    (in the terminal window on MacOS and Linux; on Windows, you can double-click on the drjava-rxxxx-mint-ryyyyy.jar file)

  2. Look at the right side of the in the “Compiler Output” pane. There is a drop-down box labeled “Compiler”: Select “Mint 6.0_16-Mint” (or something similar). If you don’t see it in the list, DrJava could not find Mint. Check that you installed Mint correctly.
  3. Open a Mint program (“File/Open” menu or “Open” button)
  4. Compile it (“Tools/Compile All” menu or “Compile” button)
  5. Run it (“Tools/Run Document’s Main Method” menu or “Run” button). The output will be displayed in the “Interactions” pane.

Note that the interpreter in the Interactions pane does not understand Mint. It is just a Java interpreter. Brackets and escapes are only recognized in programs in the Definitions pane (source editor).

(Re-posted from The Java Mint Blog)

Share
Posted in DrJava, Mint | 1 Comment

Print This Post Print This Post  

Goodbye Computer Shopper, Hello Esquire?

Please be advised that Computer Shopper magazine has ceased publication after the April 2009 issue.
[…] Special arrangements have been made with Esquire magazine to service your subscription for its full remaining term. You will receive three issues of Esquire for every issue remaining on your Computer Shopper subscription.

(Emphasis in bold mine)

Cripes, I’m going to receive “Esquire” until January 2014! So far, “Esquire” looks like “Maxim”, but with manlier, more mature cologne samples.

The other magazine that I received today was “The Bent”. Now that’s a quality publication ;-)

Share
Posted in Ramblings | Leave a comment

Print This Post Print This Post  

DrJava Mint Branch Merged Back into Trunk

I just merged the trunk-mint branch of DrJava back into the trunk and made a new weekly release (@ I actually issue these “weakly” releases more often than just weekly. It’s just a convenient mechanism to benefit from the auto-update feature. @): drjava-weekly-20090929-r5094.jar.

Share
Posted in DrJava, Mint | Leave a comment

Print This Post Print This Post  

Musings about Facebook Application Privacy

After reading the ACLU’s report about Facebook app privacy problems and taking the quiz demonstrating them, What Do Quizzes Really Know About You?, I was a little upset at first.

The privacy settings just seemed completely insane. Let’s use one’s sexual orientation as (spicy) example and assume we have two facebook users, A and B, with the following privacy settings:

A does not allow apps to see A’s sexual orientation.
A does allow all other accesses.
B does allow all accesses.

If B now runs an application, it would seem like B’s application shouldn’t see A’s sexual orientation, because A denies applications that piece of information. However, it seems like Facebook uses B’s privacy settings, which grant all accesses. The result is that B’s application can see A’s sexual orientation. This seems wrong.

I’ve realized, though, that in principle there is nothing wrong with this. Since B can see A’s sexual status, B’s application could ask B to manually enter it, and the application would still know about it. The desire to apply A’s privacy settings to B’s applications really only prevent automation, not the spread of information.

I would still like Facebook to change this, but if I really want to maintain my privacy, I probably have to abstain from using Facebook at all: The least fixpoint of entities that have my information is not small at all.

PS: Now I am going to post this on Facebook.

Share
Posted in Ramblings | Leave a comment

Print This Post Print This Post  

OpenJDK Compatibility for ConcJUnit

I just made a new ConcJUnit release available on SourceForge: version 20090927.

While working on integrating Mint into DrJava, I tested it on Mac. Since Mint requires Java 6, that involved using Soylatte, and Soylatte is based on OpenJDK. To my surprise, Mint did not work in DrJava. Upon investigation, this was only the case when ConcJUnit’s “lucky” warnings were also enabled.

So the problem wasn’t actually in Mint, it was in ConcJUnit. I even made a note about this incompatibility.

The problem is some missing method in the Float class:

Error occurred during initialization of VM
java.lang.UnsatisfiedLinkError: java.lang.Float.floatToIntBits(F)I
        at java.lang.Float.floatToIntBits(Native Method)
        at java.lang.Math.(Math.java:801)
        at edu.rice.cs.cunit.concJUnit.ThreadSets.addThreadStarted(ThreadSets.java:24)
        at java.lang.Thread.start(Thread.java:593)
        at java.lang.ref.Reference.(Reference.java:145)

I don’t quite know what is going on here, but I circumvented this issue by not using the Math class. I just had to write my own Math.min method.

Share
Posted in Concurrent Unit Testing | Leave a comment

Print This Post Print This Post  

Running Mint Programs in DrJava

I have now managed to hack DrJava and Mint together. I still have to improve the source, because right now a few things are hard-coded, but it is a working proof-of-concept.

Welcome to DrJava.  Working directory is C:\Program Files\JavaMint\langtools\mintTest
> java edu.rice.cs.mint.runtime.Mint Power_For
131072.0
> 

This is the output for the Mint program

import edu.rice.cs.mint.runtime.Code;
public class Power_For {
public static void main(String[] args) {
final double x = 2;
int n = 17;

Code c = <| 1.0 |>;
for(int i=0; i;
}

System.out.println(c.run());
}
}

It is a bit inconvenient because you have to invoke the Mint launcher, edu.rice.cs.mint.runtime.Mint, but that can be changed too.

The last problem that I had was the class path when the compiler is invoked at runtime. It took some time to understand that, because instead of saying something like “Class not found”, the error message was “Variable not found”. But because the compiler didn’t find a class definition for a certain symbol, it assumed the symbol had to be a variable.

More information later.

Share
Posted in DrJava, Mint | Leave a comment

Print This Post Print This Post  

Installing JavaMint on Linux

Here are some quick instructions on how to download and install Java Mint.

Linux

  1. You need Sun’s JDK 6 installed.
  2. Download the “binaries only” Java Mint zip file from the Java Mint implementation page. In this example, I have saved the file in my home directory, i.e. at /home/mgricken.
  3. Open a console.
  4. Change into the /usr/local directory:
    cd /usr/local
  5. Unzip it as root. This means you have to type in your password:
    sudo unzip /home/mgricken/JavaMint-r13871-binaries.zip
  6. Set the MINT_HOME and PATH environment variables:
    export MINT_HOME=/usr/local/JavaMint
    export PATH=$PATH:$MINT_HOME/langtools/bin
  7. To make this permanent, edit your .bash_profile or .bashrc file and put the two lines from step 6 line at the end of the file.

Now you can compile programs using mintc and run them using mint.

mintc Power.java
mint Power

There are samples in the /usr/local/JavaMint/langtools/mintTest directory. You cannot compile them there, however, because the directory is read-only unless you are the root user. So unzip the Java Mint implementation zip file somewhere else, e.g. in /home/mgricken/JavaMint.

(Re-posted from The Java Mint Blog)

Share
Posted in Mint | Leave a comment

Print This Post Print This Post  

Mint and DrJava Class Loader Issues

I’m still trying to integrate Mint into DrJava, and I’m running into a problem with the class loaders in Mint and DrJava.

If I understand the class loader inside the Interaction JVM correctly (a PathClassLoader, I believe), it can change the class path dynamically, and that way it can find classes with different source roots. Once a program runs, though, the program uses the normal system
class loader, which doesn’t necessarily have the same class path as the Interaction JVM class loader.

Now I need to find a way to access the Interaction JVM class loader, so I can set it as parent for Mint’s class loader, or I need to find a way to approximate this.

Share
Posted in DrJava, Mint | Leave a comment

Print This Post Print This Post  

DrJava with Mint Compiles on Windows, Mac and Linux

The DrJava built from my trunk-mint branch now manages to compile Mint programs on all three major operating systems: Windows, Mac and Linux.

I had to make a bugfix in the Mint compiler (I will make a new release soon), and I don’t quite know why we never ran into this. Perhaps the Sun JDK implements the compiler in a slightly different way than OpenJDK or Apple? We forgot to make the bracket statement case a no-op in the TreeScanner, and that caused an assertion, but only on Windows. I’m convinced, though, that this fix is correct, so I’m making it without investigating this difference further.

DrJava still cannot run Mint programs, but that shouldn’t be too difficult.

Update

The new release of the Mint compiler is available now: JavaMint-r14089 (with source).

The changes are minimal and only matter inside of DrJava or when used on the Linux command line.

Share
Posted in DrJava, Mint | Leave a comment

Print This Post Print This Post  

DrJava with Mint on Mac “Cosmetically” Closer

Sweet! DrJava with Mint on the Mac just came within reach, or at least as close as it is on the other operating systems. For some reason, when I ran DrJava under Soylatte and X11 earlier, no compilers showed up. I thought there were some more serious problems with running DrJava in that environment, but it was something quite trivial.

In revision 5078, I reverted a “cosmetic change” of x+y to x + y that had been done using a global search-and-replace. Unfortunately, the change was also done inside string constants, and thus regular expressions. And the regular expression \\d+ is not the same as \\d + .

Interestingly, the change doesn’t show up in SourceForge’s diff or my default svn diff (svn diff --diff-cmd diff -x -uw /path/to/file) because it’s whitespace only.

This is an example why I really despise cosmetic changes.

Share
Posted in DrJava, Mint, Ramblings | Leave a comment

Print This Post Print This Post  

Mint in DrJava is Tricky

I’ve been trying to get the Mint compiler to work inside DrJava. This has turned out to be more tricky than I thought.

The preempting class loader that we use to load different compiler adapters is still giving me headaches, and the fact that the “Mint SDK” is only a partial JDK (really only a replacement for the tools.jar file) means that I can’t use the same mechanism that is used to load a Java compiler to make the Mint compiler accessible. Instead, the Mint compiler needs to find Mint and a matching JDK… What exactly matches? Oh, I don’t really know right now.

Additionally, on the Mac Mint requires SoyLatte. We haven’t tested it with Apple’s implementation of Java 6 yet. Running DrJava with SoyLatte means running it in an X11 environment, and that means more headaches…

And all of this would only get us to compile Mint programs in the Definitions Pane. In the Interactions Pane, we would still only have Java. I’ve worked on this for a week and a half now, and I’m still far from being marginally successful. I think I should be able to get the Definitions Pane to work on Windows and Linux. But is that worth it?

Share
Posted in DrJava, Mint, Ramblings | Leave a comment

Print This Post Print This Post  

Updated CV and Resume

After attending an excellent workshop on converting CVs to resumes by the Rice Center for Student Professional Development, worked on improving my resume a bit.

First of all, I created two versions, a shorter resume (pdf) and a longer, complete curriculum vitae (pdf).

In the CV, I have included more information on my publications. Both documents still need work, but I’ll have a chance to improve them at future CSPD events.

I also changed the embedded PDF viewer from pdfmenot.com to the Google Document Viewer.

Share
Posted in Uncategorized | Leave a comment

Print This Post Print This Post  

Legal immigrants battle red tape

I noticed that the Houston Chronicle article I was interviewed for isn’t available on the Chronicle website anymore, so I wanted to re-post it on my blog.

From the Houston Chronicle, Jan. 9, 2009:

Legal immigrants battle red tape

Pakistan native Adeel Mehmood started building a life in Houston after the U.S. government granted him asylum more than two years ago.

He graduated from the University of Houston, settled into a home in Garden Oaks and saved money from his restaurant job to buy his dream car: a new Toyota Camry.

The 25-year-old still faithfully makes payments on the Camry — and on his insurance — even though the state of Texas in December denied his application to renew his driver’s license, citing a new policy that took effect Oct. 1 requiring specific documentation to prove an applicant’s legal immigration status.

Three months after the policy took effect, critics are pointing to a growing list of cases involving legal immigrants who have been significantly delayed or outright rejected in their efforts to get or renew licenses, despite being authorized to live and work legally in the U.S.

“I have always maintained my legal status,” Mehmood said. “It’s not fair to people who want to live here and follow the law.”

Under the policy change, only applicants who have documents showing they have permission to stay in the U.S. for at least six months are eligible for Texas driver’s licenses.

But immigration attorneys are reporting that people who meet that criterion — but are unable to produce documents required by the DPS to prove their legal status — are still being turned away.

For example, Mehmood said he was rejected by the DPS after being told his letter from U.S. Citizenship and Immigration Services granting him asylum wasn’t specifically listed on DPS’s list of acceptable forms.

The Texas chapter of the American Immigration Lawyers Association is pushing for revisions to the policy, adopted by the Texas Public Safety Commission in August, saying the list of acceptable DPS documents needs to be expanded to include several forms of legal status that allow for a six-month stay or longer in the U.S. They also are pushing the state to make allowances for delays in processing times sometimes caused by USCIS.

“This is going to end up impacting lots and lots of people,” said John Nechman, a Houston immigration attorney. “Every day there seems to be another example.”

Designed to curb fraud

Supporters of the new policy, including Gov. Rick Perry, said the state is safer because of the more stringent document checks, which are designed to stop illegal immigrants from getting licenses and to combat fraud and identity theft. The agency has issued more than 15,000 “visitor” licenses to immigrants statewide since October, said Tela Mange, a DPS spokeswoman.

Allan Polunsky, chairman of the Public Safety Commission, which oversees the DPS, said the policy change was not intended to deny legal immigrants the opportunity to drive.

“If there is a problem in the process, then it should and will be addressed,” Polunsky said. “We have to look at all the facts before we make any changes, but certainly we want to be fair.”

D. Jackson Chaney, an immigration attorney in Irving, said the DPS did not consult any immigration lawyers or experts when it put together the rule and left out several forms of legal status that allow immigrants to stay in the country beyond six months. The list includes refugees as well as some immigrants who were granted green cards before those documents had expiration dates.

“They’re being denied licenses on ridiculous grounds, frankly, because DPS simply does not know immigration law,” Chaney said. “It’s really a mess.”

Drivers License

Paperwork delay

In some cases, even though driver’s license applicants have immigration documents that appear to expire within six months, they may still have legal status from USCIS as long as they have a pending application for an extension, attorneys said. But it can sometimes take immigration officials six to 12 months or longer to process the paperwork, leaving applicants unable to drive legally for months at a time.

Mathias Ricken, a doctoral candidate and computer science instructor at Rice University, made four trips to the DPS office in November and December to get his temporary driver’s license approved.

Ricken, who is in the U.S. on a student visa from Germany, called ahead on Nov. 19 to find out what documents he needed, but each time he went to the office, he was asked for more. He eventually got approved for the license after presenting documents including: his Texas ID card, his German passport, three different immigration forms, a Social Security card, a certificate of enrollment, a tuition receipt and a signed and stamped letter from the director of Rice’s Office of International Students and Scholars.

The letter was not required, but Ricken thought it might help. “I think it’s right to require that you identify yourself in the proper way and show that you are in the country legally,” he said. “The problem is more in the details.”

Unusual case

The problem has turned into more than a nuisance for Mehmood.

His driver’s license expired in November. Mehmood has made multiple visits to DPS offices since then, each time carrying a thick three-ring binder of immigration documents and his work authorization.

Mehmood said he was told that his letter granting asylum and other immigration documents were not sufficient proof of his legal status. He also was told he was ineligible because his “I-94,” a standard U.S. customs form for foreigners, had no expiration date, which is common for asylees, who are allowed to stay in the U.S. indefinitely.

Mange, the DPS spokeswoman, said she would look into Mehmood’s case.

Note: I am a legal non-resident alien, not an immigrant.

Share
Posted in Pictures, Uncategorized | Leave a comment

Print This Post Print This Post  

I Am (4*weakly+strongly)/5 Optimistic

The POPL 2010 reviews of our Mint paper are in. We got four reviews of “weak paper, but I will not fight against it” and one review of “strong paper, I will champion it at the program committee meeting”.

We now have another day to submit minimal comments that address some misunderstandings. A lot of the comments are really useful, so thank you for your feedback, reviewers!

Share
Posted in Mint | Leave a comment

Print This Post Print This Post  

New Mint Benchmarks: Overhead of Boxing/Unboxing

I was working on the next tutorial for the Java Mint Blog, and in writing some new small programs realized that boxing and unboxing has a pretty large impact. It is much better to use primitive types. That also implies that we can’t use generics for the staged function.

This generic ILambda with R=Double, P=Double has bad performance:

Code> codePowerOf17 =
<| new ILambda() {
public Double apply(Double param) {
return `(spower(<|param|>,17));
}
} |>;
ILambda stagedPowerOf17 = codePowerOf17.run();

This non-generic ILambda_double_double where return type and parameter type are fixed to primitive double is much better:

Code primCodePowerOf17 =
<| new ILambda_double_double() { public double apply(double param) { return `(spower(<|param|>,17));
}
} |>;

% mint BoxingUnboxingExpense
power(2, 17)
       10818348
stagedPowerOf17.apply(2.0)
       10452177
primStagedPowerOf17.apply(2.0)
       43746

This is for 200 million iterations. With boxing/unboxing overhead, the staged function barely breaks even.

I rewrote the benchmarking code to put less emphasis on the boxing/unboxing and re-ran our benchmarks. A lot of them stayed the same, but some power and fib_let gained another factor of two!

power                   9.066x (up from 4.552)
fib_let                 8.834x (up from 4.107)
eval-fact               10.384x (up from 8.390)
loop-unroll             1.580x (slightly up from 1.439)
power_let               5.703x (about same)
partial-loop-unroll     0.965x (about same, 0.942x)
serialize               18.433x (about same)
mmult                   0.913x (slightly down from 1.180)
mmult-sparse            1.134x (slightly down from 1.469)
eval-fib                9.911x (slightly down 10.210)
Share
Posted in Mint | Leave a comment

Print This Post Print This Post  

Higher Order Functions in Java

In order to understand future examples, we first have to discuss how to use higher-order functions in Java, and how to write anonymous inner classes. This post will have nothing to do with multi-stage programming.

Let’s write a program that can print out data tables for different mathematical functions. For example, for a function that multiplies by two, f(x) = 2x, we want to print something like this:

x                      f(x)
       -5.0000000000       -10.0000000000
       -4.0000000000        -8.0000000000
       -3.0000000000        -6.0000000000
       -2.0000000000        -4.0000000000
       -1.0000000000        -2.0000000000
        0.0000000000         0.0000000000
        1.0000000000         2.0000000000
        2.0000000000         4.0000000000
        3.0000000000         6.0000000000
        4.0000000000         8.0000000000
        5.0000000000        10.0000000000

We can write a function like this:

public static void printTableTimesTwo(double x1,
double x2,
int n) {
assert n>1;

double x = x1;
double delta = (x2-x1)/(double)(n-1);
System.out.println("x f(x)");
System.out.printf("%20.10f %20.10f\n", x, x*2);
for(int i=0; i<(n-1); ++i) { x += delta; System.out.printf("%20.10f %20.10f\n", x, x*2); } }

The parameter x1 determines the lower end of the interval, x2 the upper end, and n determines how many values should be printed. n needs to be at least 2 to print out the values at x1 and x2. We can generate the table above with this call:

printTableTimesTwo(-5, 5, 11);

What if we want to print out the values of a different function, for example f(x) = x + 4? We can write a new function:

public static void printTablePlusFour(double x1,
double x2,
int n) {
assert n>1;

double x = x1;
double delta = (x2-x1)/(double)(n-1);
System.out.println("x f(x)");
System.out.printf("%20.10f %20.10f\n", x, x+4);
for(int i=0; i<(n-1); ++i) { x += delta; System.out.printf("%20.10f %20.10f\n", x, x+4); } }

This involves a lot of code duplication, though. The only parts that actually differ are the two occurrences of x*2 and x+4. How can we factor that difference out?

Let's write an interface that we can use for any kind of function that takes in one parameter and returns one parameter f(x) = y is an example of such a function.

public interface ILambda; {
public R apply(P param);
}

This interface is called ILambda and it has one method, apply. We used Java generics and didn't specify the return type and the type of the parameter; instead, we just called them R and P, respectively. A function that takes in a Double and that returns a Double, like f(x) = y, can be expressed using a ILambda. A function taking a String and returning an Integer would use ILambda.

Now we can write our f(x) = 2x and f(x) = x + 4 functions using ILambda:

public class TimesTwo implements ILambda {
public Double apply(Double param) { return param*2; }
}
public class PlusFour implements ILambda {
public Double apply(Double param) { return param+4; }
}

Now we can write one printTable method that takes in an ILambda called f representing the function, in addition to the parameters x1, x2 and n, as before:

public static void printTable(ILambda f,
double x1,
double x2,
int n) {
assert n>1;

double x = x1;
double delta = (x2-x1)/(double)(n-1);

// f.apply(x) just means what f(x) means in math!
double y = f.apply(x);
System.out.println("x f(x)");
System.out.printf("%20.10f %20.10f\n", x, y);
for(int i=0; i<(n-1); ++i) { x += delta; y = f.apply(x); System.out.printf("%20.10f %20.10f\n", x, y); } }

Note that when we want to print out the y-value, we just write f.apply(x), which looks very similar to f(x) in mathematics. It means exactly the same.

We can print out the tables for our two functions using:

printTable(new TimesTwo(), -5, 5, 11);
printTable(new PlusFour(), -5, 5, 11);

We have to create new objects for the functions: The first time we call printTable we pass a new TimesTwo object; the second time, we pass a new PlusFour object.

We can now define as many functions as we like without having to rewrite the printTable function. For example, we can easily write a square root function and use it very easily:

public class SquareRoot implements ILambda {
public Double apply(Double param) {
return Math.sqrt(param);
}
}

// ...

printTable(new SquareRoot(), -5, 5, 11);

The really neat thing is that we can even define a new function on-the-fly, without having to give it a name. We do that using anonymous inner classes in Java. Here, we call printTable and pass it a new object that implements ILambda.

printTable(new ILambda() {
public Double apply(Double param) {
return param*param;
}
}, -5, 5, 11);

We define a new ILambda from Double to Double without giving it a name. When we use anonymous inner classes, we need to fill in all the methods that are still abstract. Here, it is just the apply method.

The method printTable is now a "higher order function", because conceptually it is a function that takes another function as input.

Questions:

  1. What does the anonymous ILambda in the example above compute? What's the mathematical function it represents?
  2. How would you print a table for the function f(x) = x2 + 2x?

You can download the complete source code for the examples here:

(Re-posted from The Java Mint Blog)

Share
Posted in Mint | Leave a comment

Print This Post Print This Post  

Photos from My COMP 600 Practice Talk

Jennifer Harris was kind enough to video-tape my practice talk and make the recording available to me, and she did so in record time so I could watch myself before I went to Calgary. Thanks, Jennifer!

Here are some frames from the video:

Share
Posted in Concurrent Unit Testing, Graduate School, Pictures | Leave a comment

Print This Post Print This Post