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
-
I haven’t thought this through completely:-)
-
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:
-
$i is recognized as the object to act on.
-
It’s an
Integer
, so the correspondingClassCommand
is looked up and executed with+
and10
as arguments. -
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 newInteger
.
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.