FINAL PROPOSAL: Implementing Modified CICE and Block-Attached Calling

Haitao Sun alexhsun at gmail.com
Sat Mar 1 23:53:44 PST 2008


                        FINAL PROPOSAL

      Implementing Modified CICE and Block-Attached Calling

                          SUN Haitao

I propose implementing a Java compiler with the following features:

* A new form of instance creating expression based on CICE[2] (with
some modification).

* A general control abstraction mechanism called "Block-Attached
Calling" (like "blocks"[1] in Ruby).

* An annotation to indicate the "major" method of concrete classes.
(So they can be treated like single-abstract-method types)

1. Design Goals
===============

The major goal of this proposal is to try to add an expressive
control abstraction mechanism to Java in an easy-to-grasp way.

The minor goal of this proposal is to try to find out an attractive
solution for those who don't want closures in Java 7.

A less expressive mechanism often is bundled with the following
problems:

1) It can't express some useful abstractions. That takes programs
both hard to write and hard to read.

2) It's not cool enough. Then no one want to try it in early stage.
Without hundreds of thousands of explorers, it's pretty hard to know
the feature's potentials, limitations, and proper usage.

3) Similar mechanism will be introduced again and again to express
more useful abstractions. That hurts orthogonality and brings
complexity.

A hard-to-grasp mechanism often have the following short-comings:

1) It's hard to learn. Smart developers can certainly handle this
problem, but they will yield much more and make a better world
by focusing on real problems.


2) It's hard to implement and optimize. The absence of optimized
implementation will prolong adoption cycle, and being adopted fast is
a key factor to success in market.

2. Introductions
================

All three features proposed are inspired by original CICE proposal.

2.1 The modified CICE

I propose the following modification to CICE:

1) For concrete classes, the name of the method to be override can be
used to solve ambiguity.

2) When being used as arguments, the type part is optional.

2.2 the BAC mechanism

I propose a mechanism called Block-Attached Calling. It works like
Ruby blocks. So we can test whether mechanisms to define control
constructs are worth adding.

The main idea of BAC is that if the last argument is an CICE, its body
can be placed after the right parenthesis of the method calling. If
the CICE has a formal parameter list, it should be quoted with "|" and
used as the last argument.

If we adopt this proposal, we can write the following samples:

    // Loop Abstraction
    // ``repeat`` is an user-defined method
    repeat(3, |int i|) {
        //do something
    }

    // Resource Management
    // ``with`` is an user-defined method
    with(resource) {
        //do something
    }

There is no public draft specification of BAC yet.

2.3 The "major" Annotation

I propose an annotation called "major" to indicate the "major" method
of concrete classes.

Concrete classes with one method annotated as "major" can be treated
like single-abstract-method types. The "major" method will be treated
as the single abstract method.

3. Deliverables
===============

The planned deliverables are:

1) The specification of the Block-Attached Calling mechanism and the
modified CICE.

2) The source code of the prototype compiler and related test suite.

3) The implementation and javadoc of the "major" annotation.

4. Existing Works
=================

The compiler will based on an SVN version of the compiler in OpenJDK.

Some further ideas may be inspired by BGGA[3] proposal and FCM[4]
proposal.

5. Dependencies on Sun
======================

There are no known dependencies on Sun with following exceptions:

* The compiler is based on the compiler in OpenJDK.

* "SUN" happens to be my surname.

6. Related Works
================

[1] Programming Ruby
    http://ruby-doc.org/docs/ProgrammingRuby/html/tut_containers.html
[2] Concise Instance Creation Expressions: Closures without Complexity
    http://docs.google.com/View?docid=k73_1ggr36h
[3] Closures for the Java Programming Language
    http://javac.info/
[4] First-Class Methods
    http://docs.google.com/View?docid=ddhp95vd_0f7mcns



More information about the challenge-discuss mailing list