The Artima Developer Community
Sponsored Link

Heron-Centric: Ruminations of a Language Designer
New HeronFront with Classes and Delegations
by Christopher Diggins
January 24, 2006
Summary
I've just uploaded the latest Heron version which now supports classes, structs and delegations

Advertisement

In the previous version of HeronFront a class would have to be written in C++, and the interface (previously a "trait") would have to be written in Heron. Well that was kind of confusing to say the least, so I finally managed to get the HeronFront translator to handle classes. A Heron class looks more or less like a class in C++/Scala/Python:

class string 
{
  delegates
  {
    Stack[char] : f;
  }
  fields 
  {
    stack[char] f;  
  }
  public 
  {
    def _init(cstring x) {
      while (x != NULL) {
        push(*x++);
      };
    }    
    def _eq(self& x) : self& {
      clear();
      _plus_eq(x);
      return *this;
    }
    def _plus_eq(self& x) : self& {
      uint i=0;
      while (i < x.count()) {
        push(x[i]);
      };
      return *this;
    }
    def _plus(self& x) : self {
      return *this += x;      
    }
  }     
}
In a class all fields are private, while in a struct all fields are public. This is intended to assure that the interface of a class is only made up of functions. This may lead to other features in the future, like the ability to ellicit an interface from a class.

The _eq, _plus, and _plus_eq functions are operator overloads. The _init function is the constructor. There are a few extra neccessary semicolons (why they are needed is a very long story related to the future ability to pass code-blocks to macros).

The delegation specification automatically generates functions which forward an interface's required functions to a member field.

The latest version of HeronFront is very unstable, but I posted it to http://www.heron-language.com/downloads.html for anyone who might be using the HeronFront / YARD code base for their own work.

For the time being I have to figure out why my vlist-based string class is so much slower than the GCC standard library implementation of a string!

Talk Back!

Have an opinion? Readers have already posted 1 comment about this weblog entry. Why not add yours?

RSS Feed

If you'd like to be notified whenever Christopher Diggins adds a new entry to his weblog, subscribe to his RSS feed.

About the Blogger

Christopher Diggins is a software developer and freelance writer. Christopher loves programming, but is eternally frustrated by the shortcomings of modern programming languages. As would any reasonable person in his shoes, he decided to quit his day job to write his own ( www.heron-language.com ). Christopher is the co-author of the C++ Cookbook from O'Reilly. Christopher can be reached through his home page at www.cdiggins.com.

This weblog entry is Copyright © 2006 Christopher Diggins. All rights reserved.

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us