Page 1 of 5

If you were to create a programming language...

Posted: Fri Dec 20, 2013 2:26 am
by iPoisonxL
If you were to create a programming language, what would the main syntax be like, and why?

I have always dreamed of a completely readable language. Not because it'd be "easier" to code with, no, it'd be much harder. I just always thought it'd be pretty cool. Here's an example of my "dream language":

Code: Select all

(this is a variable declaration and an if statement. 
oh and this is a multi-lined comment.
There is no single lined comment, you always need to close the parentheses.)

variable name is equal to true
if name equals true, out "hi", if not, out "bye". 

(this is obviously bunched up in one line and could be whitespaced/newlined as much as needed)

(analysis:
creating a variable called name, and setting it to true. Then, we check if name is equal to true, and then we output hi if yes. Else, we output bye.)

(basic syntax translating:
"variable" is a variable declaration
"is equal to" just means =
"equals" is ==
"," is then, or its a continuation, depending on where the last "," was.
"out" is print
"if not" is an else statement
"." usually means closing a statement)
This is just an if statement, and a variable declaration. I actually mapped out a whole file just showing off syntax for this, not sure where it went though. It had pretty cool concepts, but it was really just like a re-textured Lua.

Funny thing, I once tried to hard-code a simple language with Java, using this syntax. I somewhat succeeded, I created a "language" that could assign a variable a name and a number, and then you could print that. It's all it did, but it was interesting.

And you? What would be your dream syntax if you could create a programming language?

Re: If you were to create a programming language...

Posted: Fri Dec 20, 2013 3:27 am
by pk
You could probably implement that language in Forth :awesome:

Re: If you were to create a programming language...

Posted: Fri Dec 20, 2013 3:55 am
by szensk
Mine would look like the statically typed bastard child of Ruby and Moonscript with plug-in interfaces types ala Go. And go routines.

Code: Select all

class Number
  def self.square -> Number:
    @ * @
def square(x: Number) -> Number:
  x * x
squares = [x.square for x in 1..10]

Re: If you were to create a programming language...

Posted: Fri Dec 20, 2013 7:56 am
by ivan
iPoisonxL wrote:I have always dreamed of a completely readable language. Not because it'd be "easier" to code with, no, it'd be much harder. I just always thought it'd be pretty cool. Here's an example of my "dream language":

Code: Select all

(this is a variable declaration and an if statement. 
oh and this is a multi-lined comment.
There is no single lined comment, you always need to close the parentheses.)

variable name is equal to true
if name equals true, out "hi", if not, out "bye". 

(this is obviously bunched up in one line and could be whitespaced/newlined as much as needed)

(analysis:
creating a variable called name, and setting it to true. Then, we check if name is equal to true, and then we output hi if yes. Else, we output bye.)

(basic syntax translating:
"variable" is a variable declaration
"is equal to" just means =
"equals" is ==
"," is then, or its a continuation, depending on where the last "," was.
"out" is print
"if not" is an else statement
"." usually means closing a statement)
iPoisonxL, your language example is just syntactic sugar - I mean something like that could be implemented using macros in C/C++ alone. As soon as you introduce equations and other math expressions, the language would start to look a lot like Lua. Also, (usually) in programming the more succinct the language the better.

Recently I've been thinking about possibly a high level language centered around behavior trees. It would be centered around moving/modifying objects and could be useful in AI for games and possibly as an embedded language for robotics. Something like:

Code: Select all

  -- seek and attack player
  selector
  {
     -- wander behavior
     parallel
     {
       not sense(player)
       wander
     }
     -- attack sequence
     sequence
     {
       settarget(player)
       rotatetotarget
       shoot
     }
  }
The cool thing about behavior trees is that you can put animation/tween goals in there too.

Re: If you were to create a programming language...

Posted: Fri Dec 20, 2013 10:49 am
by Plu
I've been thinking about a language that I would like to try and implement, but the primary idea would be that it does not store its program as text at all. It would use a sort of linked graph instead. So there wouldn't be much of a syntax probably.

Re: If you were to create a programming language...

Posted: Fri Dec 20, 2013 5:28 pm
by bzSteve
Early versions of COBOL used to be a bit like what you're describing. Before the COMPUTE statement, you had to say SUBTRACT C FROM B GIVING A instead of A = B-C.

Those were dark times indeed.

Re: If you were to create a programming language...

Posted: Fri Dec 20, 2013 8:34 pm
by jjmafiae
my language:

Code: Select all

a = 5

func test()
   if a = 5 then
        print("test")
		a = 2
   end
end
it would be lua like but faster to write

Re: If you were to create a programming language...

Posted: Fri Dec 20, 2013 9:12 pm
by veethree
It would be identical to lua except you could do this:

Code: Select all

if i == 1 or 2 or 4 then

Re: If you were to create a programming language...

Posted: Fri Dec 20, 2013 9:14 pm
by Roland_Yonaba
jjmafiae wrote:my language:

Code: Select all

a = 5

func test()
   if a = 5 then
        print("test")
		a = 2
   end
end
it would be lua like but faster to write
Question. Hw would you distinguish assignment from equality tests if they all use the same operator "=" ?
I am not saying it's not possible, but it sounds quite confusing, to me.

Re: If you were to create a programming language...

Posted: Fri Dec 20, 2013 9:19 pm
by veethree
Roland_Yonaba wrote:
jjmafiae wrote:my language:

Code: Select all

a = 5

func test()
   if a = 5 then
        print("test")
		a = 2
   end
end
it would be lua like but faster to write
Question. Hw would you distinguish assignment from equality tests if they all use the same operator "=" ?
I am not saying it's not possible, but it sounds quite confusing, to me.
When i was first getting used to lua i used to always use a single = in if statements. That may be cause i was coming from vb.net which may or may not do that, don't remember.