Hypothetical Hecl

I did some ‘playing’ with Hecl the other day, to see what it might look like if implemented in a slightly different way, and I thought I’d share what I was thinking about. Keep in mind that

  1. I haven’t thought this through completely:-)

  2. It’s not something I’m going to just rush out and do in the near future. It’s definitely a Hecl 2.0 sort of idea.

My notion was to make use of the ClassCommand feature to have at least simple types be hooked directly to the relevant Java types, and dealt with through methods, rather than commands. For instance:

$i + 10

instead of

+ $i 10

Where $i is, in the first case, a Java Integer, rather than a Hecl type.

What it would be doing internally is something like this:

  1. $i is recognized as the object to act on.

  2. It’s an Integer, so the corresponding ClassCommand is looked up and executed with + and 10 as arguments.

  3. The classcommand for Integer has a + method that accepts an argument, in this case, 10, which is added to the value of $i, and returned as a new Integer.

Without a “real” (where real also means bloated, memory and space hungry) parser, Hecl is never going to have a C-like syntax – you still wouldn’t be able to do foo = 1 + 2 + 3 – but this just might make a significant amount of people more comfortable with Hecl, which would be a good thing. You could do something like this:

set i 1

while { $i < 1000000 } {
    set i [$i + 1]
}

instead of

set i 1

while { < $i 1000000 } {
    set i [+ $i 1]
}

I actually built a really simple HeclInteger class that implements <
and + as methods to Integer ObjectThings, in order to test out this idea, and it seems to run about as fast as the regular Hecl version.

I welcome any thoughts or comments on the idea.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s