The Artima Developer Community
Sponsored Link

Heron-Centric: Ruminations of a Language Designer
What's next for Heron?
by Christopher Diggins
January 25, 2006
Summary
Good question. Here is a brief summary of where I'm at and where I'm thinking of going.

Advertisement

So I successfully wrote and compiled a program using Heron which reverses the standard input.

def test() {
  string s;
  char c = getchar();
  {
    while (c != EOF) {
      s += c;
      c = getchar();
    };
    while (!s.is_empty()) {
      putchar(s.top());
      s.pop();
     };
  };
}
On my system this executes in less than 2 seconds. The executable size is just 50k, when compiled using MinGW. The comparable program written in C++ takes 100k and executes in roughly the same amount of time.

What I think is particularly cool is that the string class is exceedingly simple:

class string
{
  fields
  {
    stack[char] f_stack;
  }
  delegates
  {
    Stack[char] : f_stack;
  }
  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;
    }
  }
}

How's that for compact? What a difference delegations make. I guess to be fair I should include the Stack interface:

interface Stack[type T]
{
  inherits
  {
    Array[T];
  }
  requires
  {
    def push(T x) {
      uint old = count();
      inner;
      post(count() == old + 1);
    }
    def pop() {
      uint old = count();
      pre(!is_empty());
      inner;
      post(count() == old - 1);
    }
    def top() : T& {
      pre(!is_empty());
      inner;
    }
  }
  extension
  {
    def is_empty() : bool {
      return count() == 0;
    }
    def clear() {
      while (!is_empty()) {
        pop();
      };
    }
    def dup() {
      push(top());
    }
    def reverse() {
      if (count() < 1) return;
      int max = count() - 1;
      int n = (count() / 2) - 1;
      int i = 0;
      while (i < n) {
        swap_elements(i, max - i);
      };
    }
    def swap_elements(uint i, uint j) {
      T tmp = _subscript(i);
      _subscript(i) = _subscript(j);
      _subscript(j) = tmp;
    }
    def _plus_eq(T x) {
      push(x);
    }
  }
}

Now if you aren't impressed yet, then you probably aren't familiar with the C++ standard template library. Yes, I know you can do much of this in C#, but try comparing the execution speed and memory usage. That's right, Heron screams like a bat out of hell.

Whenever I reach a mile-stone with Heron, I usually tend to get overwhelmed and somewhat depressed by the list of things to do. It's not straightforward what the best next step is.

So the HeronFront compiler works more or less (at least for me, it'll probably bite your right arm off if you tried it). Obviously there are a lot of bugs, and no documentation. However I don't think now is the right time to start documenting the tool, and providing support to the masses. That would simply require more time and energy than I have. I think I should work on it a bit more, doing some field testing before I release it onto the public.

My current plan is to implement a HeronScript interpreter in Heron. I figure that'll reveal the nastiest bugs, and hopefully demonstrate that Heron is going to be a serious force to be reckoned with in the not-too-distant future.

Talk Back!

Have an opinion? Readers have already posted 18 comments 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-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use