Hello All,

For a while, i've been searching for a programming language suitable for small-ish devices. The main purpose of this language is scientific computing.

The implementation will byte compile and interpret, rather than native compilation. so the availability of existing compilers is not an issue.

However, one of the key capabilities of this language would be the ability to define new data types and operators on that type so that, once defined, the new type could be used rather like any existing type.

For example in C++, say, you can define `class Complex' a complex number and provide operators on `Complex' like "+" so that "a = b + c;" is a valid and useful statement when a, b and c are complex.

Unfortunately, C++ is rather too complicated to parse. i need something smaller.

The other idea is to take an existing language and extend it. For example LUA is a nice small language - only a handful of "C" files as implementation, but does not have a proper type system. AFAIK, all numbers are the same (ie floating point). There's no integer type, for example.

i'm wondering if anyone has encountered something small with a rich type system.

thanks for any suggestions,
-- hugh.
Sounds like Python would be a good choice for you, Hugh. It has a fairly complex set of types, is fast, and does byte compilation. In fact, Tari is working on an implementation of Python for the Prizm. And I am working on a Lua interpreter for the Prizm!
i understand that python is dynamically typed. this means, for my example of a = b + c; for complex numbers, it has to search for the right add method at runtime. this is totally unnecessary if it already knows the types at compile time.

languages i've seen that do this properly are all the heavily functional types like Haskell and OCaml and the like.

what i need is something more similar to traditional imperative programming but with operator overloading.
So you want..
  • Interpreted
  • Operator overloading
  • Static typing
  • Imperative style

I don't know any languages that fit all of those. Python has a rich type system but is dynamically typed, and Haskell hits the first three, but is of a functional style (Hugs provides an interpreted implementation of Haskell, unlike the de facto standard GHC, which compiles).
Check out Squirrel: http://www.squirrel-lang.org/

Object-oriented scripting language that is embed friendly and should be fast, being designed for game uses.
Hi,

Tari, yes that's about where i got to. i looked at hugs a while back.

Kllrnohj, thanks for the squirrel link. this looks really interesting. it's not quite the static typing i want but you can define metamethods. here's an attempt at starting a `Complex' class example.



Code:
class Complex
{
        constructor(_x, _y)
        {
            x = _x;
            y = _y;
        }

        function _add(z)
        {
            return Complex(x + z.x, y + z.y);
        }

        function _sub(z)
        {
            return Complex(x - z.x, y - z.y);
        }

        function _tostring()
        {
            local s = x.tostring();
            if (y >= 0) s = s + "+";
            return s + y.tostring() + "i";
        }

        x = 0;
        y = 0;
}

local c = Complex(1,2);
local d = c + c;
local e = Complex(1,1)-c;
local f = c + Complex(1.5, 0)

print(d); print("\n");
print(e); print("\n");
print(f); print("\n");

print("so far, so good!\n");


I like the small size of the code. it would be nice to have a metamethod for type conversion, or automated use of constructors. so i can say local c = Complex(1,2); c = c + 1;

rather than c = c + Complex(1,0);

i'm going to continue experimenting...
-- hugh.
Neat, be sure to keep us posted as you go. I'm learning a bit about some new languages (especially Squirrel), so I'll be interested to see where you go from here.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement