[Show all top banners]

badarkta

More by badarkta
What people are reading
Subscribers
:: Subscribe
Back to: Kurakani General Refresh page to view new replies
 JATHA
[VIEWED 2230 TIMES]
SAVE! for ease of future access.
Posted on 03-01-08 8:16 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Jatha

Bringing to Java some of the power of Lisp

Introduction

Lisp programmers have a very powerful macro system. When a Lisp programmer writes a macro it's not like a C programmer's macro; it's not just a simple textual substitution. No, when a Lisp programmer writes a macro, she has the full power of Lisp at her disposal.

Lisp macros are Lisp programs that write Lisp programs.

Jatha macros are Java programs that write Java programs.

Jatha is a preprocessor that runs arbitrary java code in order to generate the source code that the compiler sees. Using Jatha, I wrote a simple @PROP macro, that turns this:


class Foo { @PROP(String, name); }

Into this:


class Foo { private String m_name; public String getName() { return m_name; } public void setName(String name) { m_name = name; } }

Jatha "macros" are actually just regular java classes. The @PROP macro is merely a class named "PROP" that lives in the "macros" package. It has a method named expand() that can turn an argument array like {"String", "name"} into the source code for a property with get and set methods.

I have written other simple macros. The @ENUM_OBJ macro turns this one-liner:


@ENUM_OBJ(MyEnumeration, INT, "int", DOUBLE, "double")

Into this sophisticated object-based enumeration:


class MyEnumeration { public static final MyEnumeration INT = new MyEnumeration("int"); public static final MyEnumeration DOUBLE = new MyEnumeration("double"); public static int getNumElements() { return 2; } public static MyEnumeration getElement(int __index) { switch (__index) { case 0: return INT; case 1: return DOUBLE; default: return null; } } public static MyEnumeration getElement(String __name) { if (__name.equals("int")) return INT; if (__name.equals("double")) return DOUBLE; return null; } private MyEnumeration(String __description) { this.__description = __description; } private String __description; public String toString() { return __description; } }

You can write macros like these too. Try it. You'll like it.


 


Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 365 days
Recommended Popular Threads Controvertial Threads
TPS Re-registration case still pending ..
tesla stock OMG !!
Anybody gotten the TPS EAD extension alert notice (i797) thing? online or via post?
TPS for Nepal likely to extend next week
Conservative discussions
सालीको चाक
TPS To F-1 COS
Embassy of Nepal might be able to help extend TPS for Nepal
I hope all the fake Nepali refugee get deported
Those who are in TPS, what’s your backup plan?
Homeland Security revokes temporary status for 532,000 Cubans, Haitians, Nicaraguans and Venezuelans
Toilet paper or water?
Venezuela TPS lawuit
ChatSansar.com Naya Nepal Chat
Who is hottest nepali female?
ढ्याउ गर्दा दसैँको खसी गनाउच
Mamta kafle bhatt is still missing
Looking for girl
TPS for Venezuela is terminated, only 60 days extension for transition period
Tourist Visa - Seeking Suggestions and Guidance
Looking for girl
Who is hottest nepali female?
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters