Allegro.cc - Online Community

Allegro.cc Forums » Off-Topic Ordeals » My new programming language.

This thread is locked; no one can reply to it. rss feed Print
My new programming language.
axilmar
Member #1,204
April 2001

Today was a slow day at work, so I decided to dust off my programming language project. I opened a blog about it.

If anyone is interested in such stuff, you can find the Gold Parser Builder grammar file of the language in there. The grammar seems complete to me, I hope I have not forgotten any important features.

What I'd like to create is a C-like programming language but with all the bells and whistles of modern programming languages: garbage collection, a nice static type system, support object oriented programming with interfaces, support for functional programming, templates, Unicode etc, but without the problems that plug C++ or D.

For a more informative introduction to my language attempt, you can visit the blog.

I will pursue this project in my free time, hoping that I will do enough to create a usable compiler (more like a translator to C). Creating a compiler is a daunting task, so I plan to start with the basic features first, and then build upon them.

Comments would be appreciated.

kazzmir
Member #1,786
December 2001
avatar

A C replacement is a good idea and I've been thinking of a similar goal for a while. The list of features in your language (from your blog) make me think you are just recreating ocaml. Is ocaml missing any features you need? Maybe you can just write a C-like grammar and convert straight to ocaml.

Anyway, another nice feature to add is coroutines.

SiegeLord
Member #7,827
October 2006
avatar

Quote:

problems that plug ... D

Lack of good debugging facilities, IDE's and buggy compilers?

Instead of those lists, I'd prefer to have a rationale for those features. Like, why do you consider implicit conversions and casts dangerous, but are planning on including duck (note the spelling) typed interfaces, which are arguably just as dangerous? What does 'proper Unicode support' really mean?

Also, it'd be nice to see some code samples (nevermind a lack of a compiler for them), since I'd prefer to look at that rather than the grammar file itself.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Dario ff
Member #10,065
August 2008
avatar

This reminds of the time I created my own scripting language. It was ugly, but at least it had a wait command. ;D

Your language sounds promising, good luck with it.

TranslatorHack 2010, a human translation chain in a.cc.
My games: [GiftCraft] - [Blocky Rhythm[SH2011]] - [Elven Revolution] - [Dune Smasher!]

bamccaig
Member #7,536
July 2006
avatar

I think I remember you posting about this a while ago. I can't find the thread. Interesting that in 2004 you posted a thread with the exact same title. ;) Your language doesn't sound very modern, considering it has no direct type conversions or references. I can't imagine it being very well adopted.

I would prefer combining the power of C++ with the [default] safety of C# (with a rich standard library that offers all the power of your average modern standard library). That means pointers, references, and values; pointers require unsafe context and both require explicit syntax.

I see no reason to disallow pointer arithmetic (albeit, require unsafe context). What's the difference between your pointers and modern concepts of references?

SiegeLord said:

Also, it'd be nice to see some code samples (nevermind a lack of a compiler for them), since I'd prefer to look at that rather than the grammar file itself.

^ This.

axilmar
Member #1,204
April 2001

kazzmir said:

The list of features in your language (from your blog) make me think you are just recreating ocaml. Is ocaml missing any features you need? Maybe you can just write a C-like grammar and convert straight to ocaml.

From what I read about ocaml, it has some performance overhead. My purpose is to not sacrifice performance. It also has a syntax that is quite different from C, which increases the difficulty of adopting it; personally, I don't really fancy the ';;'.

Quote:

Anyway, another nice feature to add is coroutines.

Do coroutines solve any real world problems more easily than other existing features? I have not used coroutines, but I have seen some examples (e.g. consumer-producer), that can be easily achieved using lambda functions. It's an interesting feature. If you could elaborate on its usefulness...

SiegeLord said:

Lack of good debugging facilities, IDE's and buggy compilers?

Yes.

bamccaig said:

I think I remember you posting about this a while ago. I can't find the thread. Interesting that in 2004 you posted a thread with the exact same title.

Time is a prime factor in what I can do. Right now, the major projects I was working on are finished and in maintenance phase, so I have some free time in my hands.

I'll update my blog with answers to the questions posted here. Thank you for your interest.

Shravan
Member #10,724
February 2009
avatar

By the way create an allegro binding for your language. ;)

SiegeLord
Member #7,827
October 2006
avatar

Shravan said:

By the way create an allegro binding for your language. ;)

Speaking of which, how will your language be able to bind the ALLEGRO_EVENT union which is rife with pointers? You disallow them in your spec, but clearly some C libraries use that feature.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Kibiz0r
Member #6,203
September 2005
avatar

Quote:

You disallow [pointers] in your spec

Quote:

What this language will not have:
...
references; pointers are enough.

SiegeLord
Member #7,827
October 2006
avatar

Quote:

You disallow [unions with pointers in them] in your spec

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Kibiz0r
Member #6,203
September 2005
avatar

Ah.

axilmar
Member #1,204
April 2001

Shravan said:

By the way create an allegro binding for your language.

Let me create the language first :-).

SiegeLord said:

Speaking of which, how will your language be able to bind the ALLEGRO_EVENT union which is rife with pointers? You disallow them in your spec, but clearly some C libraries use that feature.

I don't want to allow pointer arithmetic; if I allow unions of pointers and integers, then I would have no safety. It doesn't matter if a pointer points to a non-gc block, because the collector will have to track pointers to the middle of objects, but pointer arithmetic can result in a wild goose chase, with unpredictable results.

I don't want to do something complicated like ADA's discriminants.

Α solution would be to define a struct compatible with ALLEGRO_EVENT type, then use external C functions to access the pointers in the struct.

By the way, I updated the blog with code samples and a section that explains better why there is no pointer arithmetic, references and casts.

anonymous
Member #8025
November 2006

I wonder about this:

//pure function; no assignment allowed
pure func swap(a : int, b : int) : [int, int] {
    return [b, a];
}

You mean assignment to the arguments - otherwise I don't see what it has to do with purity?

And are even primitives always going to be passed by reference, as this example (somewhat ill-chosen, IMO) indicates? Are the int's in the returned tuple (?) copies or references of the input?

I also wonder about the "no casts and conversions": e.g I represent the coordinates of a game object as doubles, but I will need to use integers when I want to draw it. So this language won't allow this, as "dangerous"?

kazzmir
Member #1,786
December 2001
avatar

axilmar said:

From what I read about ocaml, it has some performance overhead.

Ocaml is strongly typed and can generate very fast code. The only overhead is probably related to garbage collection which you said your language would have as well.

Quote:

It also has a syntax that is quite different from C, which increases the difficulty of adopting it; personally, I don't really fancy the ';;'.

Which is why I said write a C grammar and have your program just translate directly to ocaml.

If ocaml isn't the way to go for you thats ok, but you should at least try it. Reinventing the wheel and all that.

Quote:

Do coroutines solve any real world problems more easily than other existing features?

Mostly I use them for generators, like the `yield' stuff from c# and python. You can build coroutines directly out of continuation primitives (like shift and reset) but I doubt you would create such primitives.

Its always possible to hack together something that looks like `yield' just using lambda and mutation but its usually uglier for the user to use.

bamccaig
Member #7,536
July 2006
avatar

anonymous said:

You mean assignment to the arguments - otherwise I don't see what it has to do with purity?

I'm also confused about what a "pure" function is. :-/

anonymous said:

And are even primitives always going to be passed by reference, as this example (somewhat ill-chosen, IMO) indicates?

There will be no primitives, IIRC.

anonymous said:

I also wonder about the "no casts and conversions": e.g I represent the coordinates of a game object as doubles, but I will need to use integers when I want to draw it. So this language won't allow this, as "dangerous"?

It will, but the conversion will need to be explicitly done with a constructor as opposed to casting or implicit conversion.

Arthur Kalliokoski
Second in Command
February 2005
avatar

They all watch too much MSNBC... they get ideas.

bamccaig
Member #7,536
July 2006
avatar

I still don't see what that has to do with assignment. I do like the language's ability to put said constraint on the function, however.

Jonatan Hedborg
Member #4,886
July 2004
avatar

bamccaig said:

I still don't see what that has to do with assignment

If we're talking functional programming here, it's about not changing any global state - the only communication with the function is through the arguments and the return value.

bamccaig
Member #7,536
July 2006
avatar

If we're talking functional programming here, it's about not changing any global state - the only communication with the function is through the arguments and the return value.

To meet Wikipedia's definition of a pure function, you can't be affected by global state in any way, meaning that you pretty much can't refer to global state at all. I fail to see where assignment plays any role whatsoever. If you can't refer to global state then you can modify global state. Obviously, you should be free to assign to locals still. Saying "no assignment allowed" makes no sense.

//create inner instances
var it1 = (new List).new Iterator1;

WTF is that... :-X

axilmar
Member #1,204
April 2001

anonymous said:

You mean assignment to the arguments - otherwise I don't see what it has to do with purity?

Traditionally, swap is expressed with one intermediate initialization and two assignments:

template <class T> void swap(T &a, T &b) {
    T temp = a;
    a = b;
    b = temp;
}

Pure functions do not allow assignments, and therefore the swap function should be written as returning a tuple of swapped values, as in the example I posted.

Quote:

And are even primitives always going to be passed by reference, as this example (somewhat ill-chosen, IMO) indicates? Are the int's in the returned tuple (?) copies or references of the input?

No, this is a value-based language. If you want to pass-by-reference, you have to use pointers. Exactly as in C, that is.

Quote:

I also wonder about the "no casts and conversions": e.g I represent the coordinates of a game object as doubles, but I will need to use integers when I want to draw it. So this language won't allow this, as "dangerous"?

It doesn't allow implicit conversions. You can convert a double to an int by instantiating an int from a double, like this:

var d = 0.0;
var i = int(d);

kazzmir said:

Ocaml is strongly typed and can generate very fast code. The only overhead is probably related to garbage collection which you said your language would have as well.

Then the wikipedia article that says Xavier Leroy has cautiously stated that "OCaml delivers at least 50% of the performance of a decent C compiler"[1], and benchmarks have shown that this is generally the case[2]. should be corrected. By the way, Xavier Leroy is the lead developer of Ocaml.

Quote:

Which is why I said write a C grammar and have your program just translate directly to ocaml.

Why not translate directly to C then? I wouldn't wish to depend on anything else than gcc, which is available for most platforms.

Quote:

Mostly I use them for generators

Hmmmm...according to what generators do, the same thing can be implemented using lambdas. It's a sort of lazy computation that is threaded with external algorithms...I am not sure that this requires a specific language construct. Since the language has lambda functions, lazy computations are easy to define and encapsulate into algorithms.

bamccaig said:

I still don't see what that has to do with assignment.

Assignment is called 'destructive update' in FP lingo, which is really bad from an FP perspective. In short, assignment forces a specific order of evaluation, which can result in intractable problems. Having the ability to have pure functions allows the user to avoid the problems.

Pure functions, by definition, can only invoke other pure functions, and therefore the whole computation becomes much easier to optimize and reason about. At least that's what they say.

Vanneto
Member #8,643
May 2007

I think he got pure functions wrong, as far as I understand as long as you don't modify the global state you are free to do anything you want in the function.

Simply put, a pure function is a function that returns exactly the same output for a constant input. sin,strlen are both pure functions yet I doubt they don't have local variables.

EDIT:
Then again, its your programming language. Call it whatever you want. :P

In capitalist America bank robs you.

bamccaig
Member #7,536
July 2006
avatar

axilmar said:

Assignment is called 'destructive update' in FP lingo, which is really bad from an FP perspective. In short, assignment forces a specific order of evaluation, which can result in intractable problems. Having the ability to have pure functions allows the user to avoid the problems.

Pure functions, by definition, can only invoke other pure functions, and therefore the whole computation becomes much easier to optimize and reason about. At least that's what they say.

What exactly can a function that can't assign to anything even do? ??? Unless I'm missing something, you're pretty much limited to returning some expression... :-/ If nothing in your function or the functions it can call can do any assignment then you're pretty much just making a wrapper that does nothing. :P

I like the idea of being able to have the compiler ensure that a particular function (or Hell, class) can't have any global state. That's what I think pure should do.

Arthur Kalliokoski
Second in Command
February 2005
avatar

A pure function is like a mathematical function, j = f(x);
You can assign j however you want after the function returns, but f(x) itself doesn't access anything except x and returns j (except its own intermediate temp locals or whatever).

They all watch too much MSNBC... they get ideas.

SiegeLord
Member #7,827
October 2006
avatar

Well, the ability to write imperative code inside pure functions is touted as a feature of D2, so that tells me that axilmar is right about the (lets say 'classical') pure functions to be as restrictive as that comment says. Perhaps some Haskell or some other FP person can explain this?

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

bamccaig
Member #7,536
July 2006
avatar

    //assignments; assignments are not expressions, 
    //in order to avoid errors like "if (x = 5)..."

C# handles that in a better way, IMHO. Conditional expressions must be Boolean so the compiler will error most of the time (the exception would be for an actual Boolean assignment expression). If that's what you really wanted then you would need to say if((x = 5) != 0) or something like that. It can be a pain to get used to at first when checking for null references, but overall I think it's a good rule and a better compromise than disallowing assignments as expressions.

It can be argued that you never need assignment in a conditional expression, but I find there are times when it's cleaner.

func main() {
    print("hello world");
}

Can main accept arguments directly and can it return an exit status?

Note: the blog seems to have eaten text following <>. Also, why are you using the BASIC-like not-equal-to operator?

    //for each
    foreach(var i; [1, 2, 3, 4]) { print(i);}

Is there going to be an interface that you can implement to make a user-defined type usable with foreach?



Go to: