Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

is macro substitution possible in java?

 
vishal avad
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
Anybody has any idea how to achieve macro substitution in java.
I ve following code. Which works fine in fox pro

same thing is also possible in VB
So please let me know how to access a value inside a variable's value.
please reply asap
thx in adv
vishal
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This isn't very easy in Java. Chances are good you'd want to reconsider your design to avoid needing to do this. But you can use reflection to achieve this sort of effect if you need to:
 
vishal avad
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jim
Thanx It works Fine, Sorry for my repeat post of message in begineer. Actually i m a bit confused with the level of question. It wont happen again
thanx again
vishal
 
Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Recently I was investigating macros as a way to extend a language, and here this question came
There are several interesting projects that add macro functionality to Java at various levels.
Vishal's example is simple abbreviation (an advanced variant allows parameters), Jatha can do that.
More interesting applications are where macros are a tool for building abstractions. OpenJava extends Java's reflection system by providing a programmer with "metaobject" abstraction, via which he can query a state of the program (classes, methods...) and modify it at compile time, thus adding new features to the language. (syntax extensions have only limited support).
Even more advanced approach is to allow programmer extend syntax of the language with new constructs. Java Syntactic Extender (JSE) is one such project, Metamorphic Syntax Macros is another. (the latter paper has a nice general overview of macro functionality). You can, for example, amend Java with forEach operator:
forEach(Task elt in tasks)
   elt.stop();
and whose expansion would be:
Iterator i = tasks.iterator();
while (i.hasNext()) {
   Task elt = (Task)i.next();
   elt.stop();
}
(this example is stolen from JSE paper)
As an extreme manifestation of power of macros, totally new, domain-specific languages can be build on base of a host language. On base of Java and "metamorphic syntax macros", a DSL for Web services was built. The Jakarta Tool Set (JTS) provides tools for creating domain specific languages.
[ August 11, 2002: Message edited by: Mapraputa Is ]
 
TJ Hylton
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been programming in java for only three months so at the risk of sounding dumb I ask, what is macros and what do they do?
 
Anthony Villanueva
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
macro. Map's links above are definitely worth a look.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic