From: Aman Goel
Subject: macro like construct in java ?
Date: 
Message-ID: <g9q490$2uq$1@registered.motzarella.org>
Folks,

       Is there a construct similar to Lisp macro in Java ? If not, can 
somebody tell me an indirect way of doing this in Java.

        I have a Java function in which 4 statements get repeated a lot 
for different cases. The only way I can think of, is to declare all 
those variables as members of the class(rather than local function 
variables, as they are now) and then operate on these variables in a new 
function of the same class which I will call from the present function.

	But this is not the desired way since it destroys encapsulation. It 
introduces extra class instance variables without any use for them 
except this.

Thanx,
Roark

From: Gene
Subject: Re: macro like construct in java ?
Date: 
Message-ID: <0b8554ed-374e-435e-8264-e4a543805f0d@l42g2000hsc.googlegroups.com>
On Sep 4, 10:07 pm, Aman Goel <········@usc.edu> wrote:
> Folks,
>
>        Is there a construct similar to Lisp macro in Java ? If not, can
> somebody tell me an indirect way of doing this in Java.
>
>         I have a Java function in which 4 statements get repeated a lot
> for different cases. The only way I can think of, is to declare all
> those variables as members of the class(rather than local function
> variables, as they are now) and then operate on these variables in a new
> function of the same class which I will call from the present function.
>
>         But this is not the desired way since it destroys encapsulation. It
> introduces extra class instance variables without any use for them
> except this.
>

Why would you ask Lisp folks about Java?

No there are no macros in Java.  The "Java way" is always to create a
new class.  Look at local classes. Encapsulate your current local
variables in one of those so you can get at them with a method of the
local class.

Incidently you can trivially mimic this structure in Common Lisp,
though, as you point out, a macro (e.g. with macrolet) would probably
be a less cumbersome solution.
From: Vend
Subject: Re: macro like construct in java ?
Date: 
Message-ID: <bfbd6409-3a30-4b35-bea4-a43b350f55f5@a70g2000hsh.googlegroups.com>
On 5 Set, 04:07, Aman Goel <········@usc.edu> wrote:
> Folks,
>
>        Is there a construct similar to Lisp macro in Java ?

No.

> If not, can
> somebody tell me an indirect way of doing this in Java.

There is no practical way. The way would be implementing a pre-
processor.

>         I have a Java function in which 4 statements get repeated a lot
> for different cases. The only way I can think of, is to declare all
> those variables as members of the class(rather than local function
> variables, as they are now) and then operate on these variables in a new
> function of the same class which I will call from the present function.
>
>         But this is not the desired way since it destroys encapsulation. It
> introduces extra class instance variables without any use for them
> except this.

If you are bothered by this, you can consider using an inner class
defined inside your method.

As a general rule, avoid the conceptual object-orientated analysis of
your domain interfer too much with the layout of your code.

> Thanx,
> Roark
From: Pascal Costanza
Subject: Re: macro like construct in java ?
Date: 
Message-ID: <6ic5e0Fpu1csU1@mid.individual.net>
Aman Goel wrote:
> Folks,
> 
>       Is there a construct similar to Lisp macro in Java ?

Not in standard Java. There are some macro systems developed for Java, 
but these are all just research prototypes.

  If not, can
> somebody tell me an indirect way of doing this in Java.

An indirect way in general is to use closures instead, and the way to 
simulate closures in Java is via anonymous inner classes.

Pascal

-- 
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
From: Dan Weinreb
Subject: Re: macro like construct in java ?
Date: 
Message-ID: <be28f2f8-b4ae-4c66-8f2a-4633c45c48d6@p25g2000hsf.googlegroups.com>
On Sep 4, 10:07 pm, Aman Goel <········@usc.edu> wrote:
> Folks,
>
>        Is there a construct similar to Lisp macro in Java ? If not, can
> somebody tell me an indirect way of doing this in Java.
>
>         I have a Java function in which 4 statements get repeated a lot
> for different cases. The only way I can think of, is to declare all
> those variables as members of the class(rather than local function
> variables, as they are now) and then operate on these variables in a new
> function of the same class which I will call from the present function.
>
>         But this is not the desired way since it destroys encapsulation. It
> introduces extra class instance variables without any use for them
> except this.
>
> Thanx,
> Roark

An indirect way of doing it in Java is with the Java Syntactic
Extender.  See http://people.csail.mit.edu/jrb/jse/.