Since Java's inception, the language's usefulness has increased through Sun Microsystems' introduction of new language features—ranging from inner classes to generics, annotations, covariant return types, and more. But Sun isn't the only one to extend the Java language: various third-party products have made Java more useful by introducing new language features and translating extended Java source code to Sun-standard Java.
Many programming languages pre-date Java, resulting in an enormous amount of legacy source code. Because migrating all of this code to Java is costly, other third-party products have been developed to compile legacy source code to classfiles and to interpret legacy source code. These products increase Java's usefulness by increasing Java's software base; they also extend the useful life of legacy source code.
Third-party products that extend Java or migrate legacy source code to Java (resulting in software that is part Java and part non-Java) contribute to Java's evolution—or Javalution. In this installment of Java Fun and Games, I introduce two such products: the Infiqs macro expander and the Snobol3 language interpreter.
Along with their practical uses, both products make Java programming more enjoyable and interesting. Use Infiqs to specify big decimal-based numeric expressions with simple operators, instead of writing these expressions as lengthy, hard-to-read, and error-prone sequences of constructor and method calls. Use Snobol3 to merge Snobol3 source code with Java, resulting in interesting part-Java/part-Snobol3 hybrids.
| Note |
|---|
| Unlike previous Java Fun and Games installments, which were written from the perspective of J2SE 1.4, this installment requires Java SE 5.0 (Java SE is Sun's new name for J2SE). |
Harold Kaplan's Infiqs—an intentional misspelling of the word infix—is a macro expander that lets programmers use infix operators to perform various
arithmetic operations on instances of java.math.BigDecimal. This product is distributed in the infiqs.zip distribution file, requires Java SE 5.0, and is freeware. (See Resources for a link to Kaplan's Website, where you can download infiqs.zip.)
The infiqs.zip distribution file contains the Infiqs application's Infiqs.class and Inf.class classfiles. It also contains this application's Infiqs.java source file, making it possible to modify Infiqs. Several example source files with .infiqs file extensions and an HTML documentation file round out the distribution.
Infiqs can save you time and frustration in situations where you specify complex mathematical expressions that involve BigDecimal objects. Rather than build lengthy sequences of BigDecimal object-creation expressions and method calls (which can become tedious to write and are error-prone), you specify short macros
that begin with the dec keyword. Consider the following code fragment:
BigDecimal x;
dec x = "1" + "2" ;
After specifying BigDecimal variable x, the code fragment employs an Infiqs macro to create two BigDecimal objects containing 1 and 2, to add the second object's 2 to the first object's 1, and to assign the first object's reference
to x. (Notice the mandatory space character after dec and before the also mandatory semicolon.) Macro expansion yields the code fragment below:
Archived Discussions (Read only)