language extensions? future direction?

Victor Volle <[email protected]> Fri, 26 Nov 2004 12:37:06 +0100
Newsgroups gmane.comp.java.beanshell.devel
Message-ID <[email protected]>

Hi,

I know, everyone has his pet language feature he would like to see ...

But since I am thinking of patching BeanShell myself, I wanted ask before, 
if any of the following features are planned already:

 1. "blocks" like in Ruby or Smalltalk: A code block that is used as 
    a parameter of a function, which the function then might call.
    Ruby'ish example:
 
       file.each { |line| 
          print(line);
       }

    which is a very short form of a command pattern, without the Java
    syntax glibberish:

      file.each( new Command() {
          public execute(Object element) {
              print(element);
          }
      }

    But there could also be more than one parameter to the "execute"

 2. "mixins" Yes, multiple inheritance is dangerous, and mixins
    introduce a kind of multiple inheritance, but they come in handy
    when needed. Imagine that you have multiple classes, that must 
    implement an Observer interface, but you can not use a common 
    abstract superclass? Do you implement the necessary code in each 
    class (with a delegate?). With a mixin, you write the code once,
    "mix" it into any class that needs that functionality:

      public class Observable {
         List observers = ...
         public void register(Observer ... ) { ... }
         public Observer remove(Observer ... ) { ... }
         public void notify(... ) { ... }
      }

      public class UMLModel extends Model mixin Observable {

      }

     Now the UMLModel class has all methods from Observable.
     (There are some issues with name clashes and using the
     mixin in some super class as well as in a sub class, but
     most can be solved)

 4. "macros" à la Lisp. I never really liked Lisp, but one feature
    was really great: The macro mechanism as part of the language.
    (In Smalltalk you could do similiar stuff, when I remember 
    correctly). You could redefine any method, and since syntactic
    constructs like "for", "while" and "new" are functions in Lisp,
    you could redefine them or create your own language on top of Lisp.
    This is quite a difficult feature to use, since it is like a can
    of worms, when you have to understand code where the meaning
    of "standard" constructs is changed, but on the other hand it 
    gives you an unbelievable powerful toolkit when necessary.

Perhaps some of the features I like is already in BeanShell and 
I haven't found/understood it?

What do you think?

Regards
Victor Volle


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/