Ideas on a new programming language

From Seoushi Games

Jump to: navigation, search

I've been growing weary of C++ for quite a long time but I can't seem to find an alternative that is as portable and has the features I want. The closest thing I've found to something better was ocaml, however it's syntax isn't the greatest (although I got use to it) and it completely lacks the ability for smp threading, something that I need in my current project and becoming more and more important in the future thanks to multiple cores being the normal.

I've been thinking of a new language that would be better but yet still be able to call all those invaluable c libraries. After looking around I notice that many platforms such as java and .net can actually runs different languages on the same vm and that got me thinking. Why can't I make a language that runs on top of c? The first obvious problem is that c isn't a vm, but a solution is to make a translator to c. This solves many problems such as compatibility, having to write a true compiler and best of all it will run where ever c will. I know this idea isn't original after searching for it on google but I believe it is a good one.

After I figured out that I could actually make a language like this I decided to list some features I would like to see incorporated into the C languages. It of course steals ideas from other languages but hey what doesn't now days? Anyways here what I came up with :

  • Ability to embed C with minimal effort
  • First Class functions
  • Static typing
  • collections (lists, vectors, tables)
  • objects (methods and variables)
  • closures
  • optional garbage collection



The next step of course would be to define what the language would look like. I started writing some code with those previous ideals in mind. Of course this isn't exhaustive and not even final, right now it's just a thought. Here are some examples.

Hello World

import Console

main( args )
{
	var text = "hello world"

	Console.WriteLn( text )
}


Class/Object

obj Person
{
	make( name, age, weight )
	{
		this.name = name
		this.age = age
		this.weight = weight
	}

	sayName()
	{
		Console.WriteLn( name )
	}


	name : String
	age : Int
	weight : Float
}


Array/Vector

arrayExample()
{
	var smiths[#]
	smiths.add( new Person( "bob", 45, 220.0) )
	smiths.add( new Person( "jane", 43, 120.0) )

	smiths.each( Person.sayName )
}

arrayExample2()
{
	var smiths[#] = [ new Person( "bob", 45, 220.0), new Person( "jane", 43, 120.0) ) ]

	smiths.each( Person.sayName )
}

objectAsArrayExample()
{
	[ new Person( "bob", 45, 220.0), new Person( "jane", 43, 120.0) ].each( Person.sayName )
}


Lists

listExample()
{
	var smiths[@]
	smiths.add( new Person( "bob", 45, 220.0) )
	smiths.add( new Person( "jane", 43, 120.0) )

	smiths.each( Person.sayName )
}


First class functions

addOne( x )
{
	return( x + 1 )
}

funStuff()
{
	var numbers = [ 1, 2, 3]

	numbers.each( addOne )

	// numbers would all be +1 now
}


Maps/Hash Tables

mapExample()
{
	var smiths[:]
	smiths.add( bob : 45 )
	smiths.add( jane : 43 )

	smiths.each( Person.sayName )
}

mapExample2()
{
	var smiths[:] = [ "bob" : 45, "jane" : 43 ]

	smiths.each( Person.sayName )
}


Embeding C

embedC()
{
	bob = 45
	jane = 43

	EMBED
	{
		#include <stdio.h>

		printf("bob is %i and jane is %i, bob, jane);
	}
}



So those are my thoughts so far. I have no idea if I will even attempt this and if I do it probably won't be anytime soon but I think it's a neat thought I would like to get to some day.