[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 1795 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 90 days
Recommended Popular Threads Controvertial Threads
TPS Re-registration case still pending ..
Toilet paper or water?
Mamta kafle bhatt is still missing
ढ्याउ गर्दा दसैँको खसी गनाउच
Tourist Visa - Seeking Suggestions and Guidance
Problems of Nepalese students in US
I hope all the fake Nepali refugee get deported
Are Nepalese cheapstakes?
and it begins - on Day 1 Trump will begin operations to deport millions of undocumented immigrants
From Trump “I will revoke TPS, and deport them back to their country.”
wanna be ruled by stupid or an Idiot ?
Sajha Poll: Who is your favorite Nepali actress?
अरुणिमाले दोस्रो पोई भेट्टाइछिन्
To Sajha admin
seriously, when applying for tech jobs in TPS, what you guys say when they ask if you have green card?
Travel Document for TPS (approved)
MAGA denaturalization proposal!!
How to Retrieve a Copy of Domestic Violence Complaint???
Nepali Psycho
advanced parole
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