This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Scripting business logic using kawa/scheme


>From my own experience I believe it would be a good idea for you to try
using Kawa
in your application.

Three years ago I had a project were I thought it would be useful to
combine Java
with some scripting language. I first looked at Jacl and then at Jpython
(now known
as Jython) and decided to use the later, for two reasons:

1. Python is, in my opinion, a much better language than Tcl. Especially
if you want
to use it for something more than command line scripting. On the other
hand, if all
you need is command line scripting then Tcl might be a better option...

2. To integrate Jacl with Java you need to write Jacl-Java interface
classes. When using
Jython you can directly use Java classes without having to write any
interface code, you
can even have a Jython class which inherits from a Java class!
(Python/Jython is object
oriented).

Since then I have been using Jython for many projects, and it has been
very useful.

Lately I have used JavaCC to implement some simple user-oriented
languages (and to work
around some Jython limitations), and it has also proved to be a useful
tool.

In the last couple of months I started using Kawa because I had a
problem I couldn't
solve in any other language (by this I don't mean it is imposible to
implement
it in another language, just that it would be very difficult to do so),
and I am
so pleased with the result that I am now experimenting with using Kawa
for all my
projects!

Some of the advantages of Kawa:

1. Lisp/Scheme is a very powerful language. For this project I had to
implement a pattern
compiler that translated patterns into an intermediate code, optimized
the intermediate
code, and then generated an executable program. The complete
implementation is less than
400 lines...

2. This pattern matcher was designed to extract information from HTML
pages. I first
translate the HTML to lisp list notation and then use the pattern
matcher to extract
the information. As a result of this the pattern matcher isn't tied to
HTML, it can
be used to extract information from any data which can be represented as
a lisp list,
which makes it easier to reuse for other projects. As a matter of fact,
one of the uses
we are looking into is to match rules to facts in a rules based
system...

3. Implementing new languages on top of lisp is very easy (if using lisp
notation
is acceptable for your users), which makes it an ideal environment to
build application
specific languages.

-----Original Message-----
From: kawa-owner@sources.redhat.com
[mailto:kawa-owner@sources.redhat.com] On Behalf Of Bhinderwala, Shoeb
Sent: Tuesday, August 26, 2003 6:40 AM
To: Kawa List
Subject: Scripting business logic using kawa/scheme


I would like to evaluate kawa/scheme for a re-design and simplification
of our current application to see if it is a good idea to use it, and if
others have applied it to similar problems.

Our firm is in the finance/investment management business. We currently
have a compliance system for portfolio managers that is written in Java
and that checks business rules on trades for compliance. The system
comprises of backend Java services (exposed through CORBA) that allow
trading applications to connect and invoke them.

The system allows users to create pre-defined rules against portfolios
and store them in the database. Rules are defined using a custom
grammar that is mainly based on boolean logic operations. An example
rule expression is the following: 

    (Security.IsEquity() AND Issuer.MarketCap() < 5000000)

The above expression means that it is a compliance failure if the trade
contains an equity security of an issuer with market cap less than 5
million.

The expressions are parsed by a parser (using javacc) converted to ASTs
(using jjtree) which is then used to generate Java source code that can
execute the rule. The Java source code is then compiled to bytecode and
stored in the database. The bytecode is loaded on the fly by the
application to evaluate the rules.

For the above example, the generated Java source code would use the
Security and Issuer Java business objects from the 'current context' and
use reflection to invoke the methods isEquity() and marketCap() and
check the above condition. 

We have run into a situation where the users (who create new rules) need
a more powerful and expressive language to express the rules. They would
like us to extend the grammar to include conditional logic
(IF-THEN-ELSE, COND) and even possibly FOR/WHILE loops. They want to
access more attributes/methods of the business objects and be able to
write more complex rules and expressions.

I am wondering if it is a good idea to keep making our grammar more
powerful (which involves a great deal of time and effort to deal with
parsing, tree-generation, compilation, etc) or use an existing scripting
language that can integrate with Java and possibly (which is the case
with kawa) compile the scripts directly to Java bytecode.

The only issue is that non-technical users should be comfortable writing
at least basic scripts (consisiting of boolean operations). 

Is kawa/scheme suited to solve this type of a problem. Essentially - to
move out business logic/rules from the application to scripts - so that
it is easy to create, modify, and maintain (even by non-technical
users).

What would be the advantages of kawa/scheme over other scripting
languages that also integrate with Java like JPython (based on Python)
and Jacl (based on Tcl).

-Shoeb Bhinderwala

PS: Here is an informative article on Java scripting languages:
http://www.javaworld.com/javaworld/jw-04-2002/jw-0405-scripts.html.





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]