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.
BAF
Member #2,981
December 2002
avatar

Why does implementing Allegro require pointer arithmetic? Or unions (I never really did find a valid use for them)?

axilmar
Member #1,204
April 2001

You realize that .pl has been used by perl scripts since day one right? (20+ years)

I do not intent to name my language 'pl'. I haven't given a name to it yet. 'Pl' is a working title.

Thomas Fjellstrom
Member #476
June 2000
avatar

axilmar said:

I do not intent to name my language 'pl'. I haven't given a name to it yet. 'Pl' is a working title.

I'm talking about the file extension. Its in use ;)

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

BAF
Member #2,981
December 2002
avatar

No response to my question?

axilmar
Member #1,204
April 2001

I'm talking about the file extension. Its in use

The file extension will be like the language name, just like in c/c++/java/d.

BAF said:

Why does implementing Allegro require pointer arithmetic? Or unions (I never really did find a valid use for them)?

The Allegro devs should answer this question.

Thomas Fjellstrom
Member #476
June 2000
avatar

axilmar said:

The file extension will be like the language name, just like in c/c++/java/d.

I'm just saying that the file you attached, was named with a .pl, and it obviously wasn't Perl ;)

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

axilmar
Member #1,204
April 2001

I did not know that Perl source files end in PL. Obviously, PL means Programming Language.

Thomas Fjellstrom
Member #476
June 2000
avatar

axilmar said:

I did not know that Perl source files end in PL. Obviously, PL means Programming Language.

Your file was .pl, not .PL ;) But perl Makefile.PL files use .PL, so that could be considered "taken" as well ;)

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

ImLeftFooted
Member #3,935
October 2003
avatar

I'm going to quickly register all untaken the 2 letter extensions and charge royalties to all who use them! >:(

SiegeLord
Member #7,827
October 2006
avatar

BAF said:

Why does implementing Allegro require pointer arithmetic? Or unions (I never really did find a valid use for them)?

Well, in principle everything could be implemented using a few goto's in a single function... so Allegro does not require those two features. However, when used they solve two problems which would not as easily or cleanly solvable without them.

For pointer arithmetic, I know one spot that uses them is the primitives addon. For example the function al_calculate_arc allows you to calculate the points on an arc. For maximum flexibility, the function requires regularly spaced pairs of floats... this allows for the coordinates to be actually embedded in some complicated structure. Thus, there is a stride parameter which governs the spacing between successive pairs of floats. I can't think of any other solution which would support this calling convention, which is clean and lightweight:

al_calculate_arc(&my_vtx_array[0].x, sizeof(MY_VERTEX), 0, 0, 1, 1, 0, 2 * AL_PI, -1, 10);

For unions, the place they are used are the ALLEGRO_EVENT's. The primary reason they are used here, I think, is to avoid pointers and casts that would otherwise be required to do the necessary inheritance in C.

With unions we can do this:

#SelectExpand
1ALLEGRO_EVENT event; 2al_get_next_event(queue, &event); 3switch(event.type) 4{ 5 case ALLEGRO_EVENT_KEY_DOWN: 6 switch(event.keyboard.keycode) 7 { 8 9 } 10 break; 11 case ALLEGRO_EVENT_MOUSE_AXES: 12 { 13 do_something_with_mouse(event.mouse.x, event.mouse.y); 14 } 15 break; 16}

Without unions we'd have to do this:

#SelectExpand
1ALLEGRO_EVENT* event; 2al_get_next_event(queue, &event); 3switch(event->type) 4{ 5 case ALLEGRO_EVENT_KEY_DOWN: 6 switch(((ALLEGRO_KEYBOARD_EVENT*)event)->keycode) 7 { 8 9 } 10 break; 11 case ALLEGRO_EVENT_MOUSE_AXES: 12 { 13 ALLEGRO_MOUSE_EVENT* mev = (ALLEGRO_MOUSE_EVENT*)event; 14 do_something_with_mouse(mev->x, mev->y); 15 } 16 break; 17}

The first seems cleaner to me.

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

axilmar
Member #1,204
April 2001

Your file was .pl, not .PL ;) But perl Makefile.PL files use .PL, so that could be considered "taken" as well ;)

I am not going to name my language 'pl' or 'PL' anyway.

I'm going to quickly register all untaken the 2 letter extensions and charge royalties to all who use them!

Did you have a look at the Pong program? what do you think about the language? did you like it? any suggestions? things you would do differently?

SiegeLord said:

I can't think of any other solution which would support this calling convention, which is clean and lightweight:

Wouldn't arrays do the job in this case?

Quote:

The primary reason they are used here, I think, is to avoid pointers and casts that would otherwise be required to do the necessary inheritance in C.

Another reason is memory management. With a union, you can declare the event struct in the local stack; with the inheritance solution, you receive a struct pointer, and you don't know how the memory is handled; you may either have to free it yourself, call an API function to free it etc.

BAF
Member #2,981
December 2002
avatar

I don't see where your example uses pointer arithmetic. It uses pointers, but it could just as easily have used references.

As far as unions, it looks more like a hack to me, and an ugly one at that. With proper inheritance, you wouldn't need to do that. I would rather use event handlers that get sent the most specific event type that is applicable anyway rather than a generic event loop.

As far as memory management, with a garbage collected language, you don't have to worry about things like this.

SiegeLord
Member #7,827
October 2006
avatar

axilmar said:

Wouldn't arrays do the job in this case?

I don't see how. Say I have a struct like this:

struct MyVertext
{
    float x, y;
    ALLEGRO_COLOR color;
}

I don't see a way around using stride (and thus pointer arithmetic) that would allow a generic function to access those x and y fields.

BAF said:

As far as memory management, with a garbage collected language, you don't have to worry about things like this.

We are talking about the language Allegro is written in which is C. The reason Axilmar's PL would benefit from supporting these two features is that it would be easy to bind C libraries. I remember quite well what major pain it was to bind ALLEGRO_EVENT structure in C# for the two bindings that were made for it, all because C# does not directly support those kind of structures.

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

axilmar
Member #1,204
April 2001

SiegeLord said:

The reason Axilmar's PL would benefit from supporting these two features is that it would be easy to bind C libraries. I remember quite well what major pain it was to bind ALLEGRO_EVENT structure in C# for the two bindings that were made for it, all because C# does not directly support those kind of structures.

It is a major benefit if you can map directly the C structs in the more advanced language.

bamccaig
Member #7,536
July 2006
avatar

SiegeLord said:

I don't see a way around using stride (and thus pointer arithmetic) that would allow a generic function to access those x and y fields.

#SelectExpand
1void some_function(int some_arg, int count, ...) 2{ 3 va_list ap; 4 5 va_start(ap, count); 6 7 some_vfunction(some_arg, count, ap); 8 9 va_end(ap); 10} 11 12void some_vfunction(int some_arg, int count, va_list ap) 13{ 14 int i; 15 16 for(i=0; i<count; i++) 17 { 18 type * element = va_arg(ap, type *); 19 20 ... 21 } 22}

some_function(some_value, array_size, array[0], array[1], array[2], array[3],
        array[4], array[5], array[6], array[7], array[8]);

:P

Disclaimer: I just woke up about an hour ago.
Disclaimer II: This code is not to be taken seriously.

axilmar
Member #1,204
April 2001

SiegeLord said:

I don't see how.

In C++, you can do it with template arrays. You are probably talking about C though.

Tobias Dammers
Member #2,604
August 2002
avatar

axilmar said:

About Pure funcions, it's something similar to Referential transparency [en.wikipedia.org]? It looks like Pure functions have more constraints though.

I think the usefulness of pure functions lies in the facts that they are
a) completely deterministic, and
b) entirely stateless
The function call and the function definition are enough to determine exactly what the output will be.
The fact that they are stateless makes them perfect for multi-threaded programming: rule out state, and all your code is naturally thread-safe (because there is no state another thread could mess with).

BAF said:

As far as unions, it looks more like a hack to me, and an ugly one at that.

Unions have a place in a language like C, where physical memory is transparent to the programmer. In a higher-level language, the entire concept is pretty meaningless, at least if it abstracts memory management details away from the programmer - after all, the actual bit representation of any data type is not typically documented and may change across platforms.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

SiegeLord
Member #7,827
October 2006
avatar

bamccaig said:

type * element = va_arg(ap, type *);

And how do you propose passing type to the function?

axilmar said:

In C++, you can do it with template arrays. You are probably talking about C though.

I am. This would be a cinch in C++ (or most any other language).

Now, back on topic:

The Blog said:

foo(1, 0);
foo(a = 1, x = 0);
foo(, 0);
foo(,x = 0);

The last invocation seems to partially defeat the purpose of named parameters. Why can't it be just foo(x = 0)? Can you do foo(x = 0, a = 1)? What about this:

/*
Is function overloading even supported?
*/
func foo(a : double, x = 0);
func foo(a : int, x = 0);

foo(,x = 5); //how to disambiguate?

The Blog said:

If the type is omitted, and the initializer expression is omitted as well, then the function becomes a template; the type of the variable will be deduced when the function is invoked.

So no default template arguments? And why the duplication of template declaration syntax?

Quote:

//constant variable declared using const type
var PI : const double = 3.14;

//constant variable declared using keyword
const PI = 3.14;

That seems backwards too me. Why not const var PI : double = 3.14? Or even const PI : double = 3.14 (const is on the same level as var)?

Also, you had no mention of closures in your function spec.

"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

SiegeLord said:

And how do you propose passing type to the function?

I assumed the function must already know about type in the current implementations as well. I don't know much about the C inheritance h4x, but I assume there is no template/generic h4x unless you use macros. Anyway, I don't fully understand the advanced C used in the Allegro library.

ImLeftFooted
Member #3,935
October 2003
avatar

axilmar said:

Did you have a look at the Pong program? what do you think about the language? did you like it? any suggestions? things you would do differently?

It looked a lot like C++, I didn't notice anything particularly interesting in the pong game (I might have missed something). Maybe you could over-engineer the pong game to use more cool features of the language?

Vanneto
Member #8,643
May 2007

Indeed, I meant to say that too, thought it was too rude. That Pong game looks exactly as ugly as anything written in C++ (maybe more). Not one bit different or innovative. :P

In capitalist America bank robs you.

bamccaig
Member #7,536
July 2006
avatar

He seems to have written it in a very C-like or C++-like way. :P Maybe that's because he doesn't have working compiler for his language to experiment with. :-/

axilmar
Member #1,204
April 2001

The fact that they are stateless makes them perfect for multi-threaded programming: rule out state, and all your code is naturally thread-safe (because there is no state another thread could mess with).

Indeed. The above is also valid even if you do not use threads, because modern CPUs may thread your computations.

SiegeLord said:

The last invocation seems to partially defeat the purpose of named parameters. Why can't it be just foo(x = 0)? Can you do foo(x = 0, a = 1)?

Yes, you can do that.

Quote:

What about this:

/*
Is function overloading even supported?
*/
func foo(a : double, x = 0);
func foo(a : int, x = 0);

foo(,x = 5); //how to disambiguate?

The above is invalid, because 'a', which is the omitted argument, does not have a default parameter value. I bet you meant something like this:

func foo(a = 3.14, x = 0);
func foo(a = 0, x = 0);
foo(,x = 5); //how to disambiguate?

Well, you can't disambiguate over the two functions. You will have to do a=0 or a=0.0 to solve the problem.

Quote:

So no default template arguments?

Yes, you can do default template arguments, like this:

func foo[T](a = T(), x = 0) {}

Quote:

And why the duplication of template declaration syntax?

Convenience. You can do this:

func max(a, b) { return a > b ? a  : b; }

without having to declare type parameters.

Quote:

Why not const var PI : double = 3.14

The 'var' can be ommitted since it is a constant variable anyway.

Quote:

Or even const PI : double = 3.14

The type is not required, since the init expression is obligatory. But I will put the type spec as optional, for consistency.

Quote:

Also, you had no mention of closures in your function spec.

The language will have nested classes, anonymous classes and anonymous functions which will capture the context. I will expand on this at the appropriate section of the specs.

Maybe you could over-engineer the pong game to use more cool features of the language?

I do not think I can do anything more interesting with Pong. If you have an idea that is within the 100-200 lines of code range, I will definitely write an example.

Vanneto said:

That Pong game looks exactly as ugly as anything written in C++ (maybe more). Not one bit different or innovative.

Well, there are no more things left to be discovered in computer science. There hasn't been a new truly new idea for decades. My language is certainly another evolutionary step in the line of C-derived languages, with ideas collected from the broad spectrum of existing languages. That is not bad for me, because I want a language that I can trust and that it allows a large class of programs to be easily created.

bamccaig said:

He seems to have written it in a very C-like or C++-like way. :P Maybe that's because he doesn't have working compiler for his language to experiment with.

I already have the parser, but, as it is obvious from the blog, this language is basically what I wanted from c++ (and if you remember any of my older allegro.cc posts, I frequently talked about how I wanted c++ to be).

But please, don't let this stop you from proposing new features and criticizing existing ones. I am open to suggestions, and I am interesting to new ideas and useful features that can be added to the language. I have already added some features that make it easier to interface with C programs.

SiegeLord
Member #7,827
October 2006
avatar

axilmar said:

The 'var' can be ommitted since it is a constant variable anyway.

I was objecting to the const being on the right side of the colon, since I think that constness of a variable has nothing to do with the type, and therefore should be on the left side of the colon.

"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

Do constant variables have to refer to a literal or existing constant expression (i.e., another constant variable) or can any value be used for a constant variable? It's one of those things in C or C++ that bother me because you may want to declare some unchanging value that isn't based on any literals, but you can't declare it as constant (the closest thing is a macro, which is ugly).

// In C++, not allowed:
const Color RED = Color(255, 0, 0);

// For example:
const RED = Color(255, 0, 0);

I think I recall seeing an example used like this, but I just looked in the variables post on the blog and it doesn't seem to be mentioned.



Go to: