...
Anonymous classes in Java are analogous to lambda-expressions in Scheme. The purpose of this lab is to practice writing such classes. We will use the Intermediate Full Java language level for this lab.
Lambda-expressions in Java
...
Code Block |
---|
int x_minus_y(int x, final int y) {
return (Integer)new Lambda() {
Object apply(Object arg) {
return (Integer)arg - y;}
}.apply(x);
}
|
...
What does this anonymous inner class do?
Code Block |
---|
Lambda whatIsIt() { return new Lambda() { Object apply(Object s1) { return new Lambda() { Object apply(Object s2) { return new Lambda() { Object apply(Object s3) { return s1 + " " + s2 + " " + s3; } }; } }; } }; } |
Actually the above does not compile in the Intermediate language level. In full Java syntax, the code would like the following (and would compile):
Code Block |
---|
public class Currying {
Lambda whatIsIt() {
return new Lambda() {
public Object apply(final Object s1) {
return new Lambda() {
public Object apply(final Object s2) {
return new Lambda() {
public Object apply(final Object s3) {
return s1 + " " + s2 + " " + s3;
}
};
}
};
}
};
}
}
|
...
Code Block |
---|
/** * Assuming the list dict contains Pairs, returns the list of Objects whose * n-th element is the Pair in dict whose key is the n-th element of the * list L. */ ObjectList translate(ObjectList L, ObjectList dict) { return null; // to do } |
—
Access Permissions: (Please don't edit)
...