Page 1 of 1

Language concept.

Posted: Sun Sep 06, 2009 3:42 pm
by JellyFish
I have this idea for a programming language similar to JavaScript and Objective-C. I'd like to know what you think, and maybe you could point out some issues with it.

Codename for the idea right now is Dao.

The main idea I have right now is that every statement is a call to a method of the global object. So, like how window. is prefixed to every variable in javascript, god. is prefixed to every statement in Dao (god doesn't necessarily have to be what the global object is called, I haven't yet decided). define is a method of the global object that takes one argument, the name of the property to define.

Code: Select all

define "foo";
So this is actually a global object method being called. Notice how there are no (parenthesis) to call a function/method. Method's are called by simply passing an argument to them. Arguments are comma delimited.

Code: Select all

method arg1, arg2, arg3, ...;
There are hardly any operators in Dao. Rather there are just methods/functions. Every newly define variable is an object with a default set of properties.

Code: Select all

define "foo"; //Creates the property foo
foo.equals 23;  //foo now equals 23
foo.plus 9; //foo remains 23, rather this statement returns (foo + 9) which is 32
foo.equals foo.minus 12;; //foo = foo - 12 = 11
 
Notice how there are two semi-colons on the last statement. This is because there are actually two statements there. The first being foo.equals ...;. The second being foo.minus 12;, which is passed as the first argument to the first statement. Think of a statement as just a value returned. Every statement returns a value so can then be passed as a value to a method.

The statement terminator operator not only ends the statement but is used as a delimiter too. It can act like a , (comma). For example:

Code: Select all

method 1, method 1, 2, 3; 2, 3;
is in javascript:

Code: Select all

method(1, method(1, 2, 3), 2, 3);
Also I'm thinking of being able to use the name of a parameter as a label for the argument. This way the order of the arguments doesn't matter:

Code: Select all

method arg1:1, arg2: 2, arg3: 3;
method arg2:2, arg3:3, arg1:1;
method arg3:3;
As you can see this is a very powerful concept. It is also possible to pass as many arguments to a method as you want, whether the method excepts these arguments is another thing.

This is all I have so far. I have yet to define the syntax involved for defining methods (eek, that's sounds a bit confuzling :S). Let me know what you think, and if you have any questions.

Philosophy: (now for some blab; you don't need to understand this)

left-to-right-ism: Basically the philosophy is that we write from left to right so we should program from left to right. So the code shouldn't force you to use the arrow keys much. I'm not sure how I'm going to accomplish this, but it seems like I'm doing okay at it.

self-programmable: I want the language to be very flexible, so flexible that perhaps able to program itself thus altering the language a bit. Kinda like how JavaScript is so flexible that we can actually create our own patterns. Kinda how jQuery has altered the pattern in which we access the DOM, I want Dao to be able to be extended in that way but not limited to that way.
I'm thinking of containing the entire language within the god object, or something. An example of this is would be that every literal would be an property of the god object, and it would be an object itself:

Code: Select all

11.plus 12; //Would return 23
//We could go crazy with methods for the literal classes
23.each method; //calls method 23 times
"foo".reverse null; //returns the string "foo" reversed "oof". We pass null as the first parameter just to call the function. It could of easily have been 0 or any value.

Re: Language concept.

Posted: Sun Sep 06, 2009 3:48 pm
by jackpf
Sounds cool....but just out of interest, how do you plan on creating/parsing/compiling (or whatever) this language?

Re: Language concept.

Posted: Sun Sep 06, 2009 4:12 pm
by JellyFish
jackpf wrote:Sounds cool....but just out of interest, how do you plan on creating/parsing/compiling (or whatever) this language?
I'm not sure yet. Mainly though, I wanna just focus on the definition of the language rather then the implementation. Although the implementation is important, I think a good standard goes farther.

I might implement this language into the browser. Sorta like how Objective-J has it's own preprocessor, I'd might make one for Dao. It would stand as the foundation for future implementations.

I'd like to note though on the literal objects. You noticed how I could write 23.plus 2;, but how would the preprocessor know if what's following the '.' is a method/property or a fraction part of the number? Both, fraction parts of numbers are properties. It's just a idea that needs questioning, but maybe all literals are just predefined variables themselves. Weird idea that I'd need to think about.

Re: Language concept.

Posted: Wed Sep 09, 2009 2:26 am
by JellyFish
I've decided to change one thing in the syntax. The dot operator that is used for member access has been changed to a forward-slash.

Code: Select all

object/property; //it's no longer object.property
The reason for this change is to avoid collision with numbers:

Code: Select all

23.11; //How would the preprocessor know if 11 is a fractional value or a member of 23?
23/11; //Would be a member of 23, although I'm not sure if I want to allow variables to start with numbers or not
23/toString ;

I think I have an idea of how methods are defined within Dao. As I analyse what a function is in most languages, I come to a conclusion. Functions are a block of code with a separate scrope, and that can be passed arguments and return a value. So I decided upon a simple syntax for create a function. I also decided that all functions should be first class citizens like in JavaScript, that is, make them a data type. So this is what I came up with for Dao:

Code: Select all

{
return "value";
};
In Dao, this is what is called a function literal. In other words the function is just a block of code, but is a data type like a string or number! This adds both block scope and function scope in Dao. Arguments are stored in a private array in Dao:

Code: Select all

{
args/get 0; //Calls the Array method get, which returns the element at index 0
args/foo; //Returns the element/property foo
define "myVariable", args/foo; //Defines a variable identified as myVariable with the value of args/foo
return myVariable;
};
 
define "sum", {
    define "sum", 0, "i", 0; //Define two variables: sum and i.
    loop args/length, { //loop through all arguments
        sum/plusEquals args/get i;;
        i/plusEquals 1;
    };
return sum;
};
sum 1, 2, 3, 4, 5; //Adds all the arguments together and returns the result
Notice how loop is just a global method and is passed it a number and a function. So now with this definition for a functions in Dao, functions are more like blocks of code but with a preset of private variables (i.e. args, and maybe some others).

I'm also thinking of making sum a built-in method along with other methods for other mathematical operations. I'm also thinking, for simplicity, ridding the plusEquals method and methods like it. I'm thinking that a += operation should be:

Code: Select all

define "myVar", sum myVar, 1;;
What do you think, should I do it that way?

EDIT:

I've noticed something:

Code: Select all

args/get 0;
method args;
What is args/get 0; was actually a method passed as an argument? How would we call it? My obvious reasoning for this language is to make every statement a call to a method and to be able to return a value. Sense a method is a function or block of code which is a first class literal value, this is exactly what args/get 0; is returning, so it would make sense to think that if a method returns a function that the function is callable:

Code: Select all

define; define "foo", "bar";
Take this as another example. How do we know if the second statement is a separate or a an argument passed to define? Sense when we write define; with no space between the identifier and the semi-colon, we are just returning the reference to that method. But how do we know if the return of the second call to define should be passed to the first call or not? This obviously is a problem that arouse from using the space character for method calling, instead of the traditional parenthesis syntax. But I like this syntax I've come up with simply because it's easier to type then (parenthesis) and also because it's more left-to-righty. So how do I solve this problem? I've decided that there are other means of defining the end of a statement other than the semi-colon. If you have more then one space or if there's a break character or a combination of both, it's considered a new statement:

Code: Select all

define;  define "foo", "bar"; //Not a call to the first statement
define;
define "foo", "bar"; //Not a call to the first statement
define; define "foo", "bar"; //IS a call to the first statement
So simply put you use one single space character to call a method. This also keeps the first argument on the same line as the method identifier. With this you could also do:

Code: Select all

define "Application", { define args/get 0; ; };
 
Application {
define "foo", "bar";
alert foo;
};
All this does is define a method called Application that takes the first argument as a function and calls it. We then call the Application method we defined and pass it a arbitrary function. The main point here is that the args/get 0; returns a function and in this case we call that function simply by putting a space and a semi-colon after it. I guess you could say that I'm just replacing ( with (a space) and ) with ;, but I think it fits better because every statement is a method call, it would look tedious to write:

Code: Select all

define("Application", {define(args/get(0);(); });
It looks less readable and I do cut some corners with the other syntax. For example, sense } is not a method name, the preprocessor would simply consider it the end of the function block rather then a argument to a method call.

Anyhow, let me know what you think of the idea so far, and if you spot anything that could be a problem.

Re: Language concept.

Posted: Thu Sep 10, 2009 12:23 am
by JellyFish
How can inventing a own programming turn a profit? How do frameworks earn money, like jQuery?

Re: Language concept.

Posted: Thu Sep 10, 2009 3:25 am
by jackpf
Hmm...sounds interesting, but with the foward slash, how would you know if the user wasn't trying to divide? I think I prefer the idea of the periods...since it's more conventional. And no, I wouldn't allow variables to be called integers.

But I guess PHP and stuff get their money from advertising. The ones that cost money, like ASP obviously make their money from selling the compiler/parser...although I'm not sure.

Re: Language concept.

Posted: Thu Sep 10, 2009 3:41 am
by JellyFish
Actually there is no division operator in Dao. There is a division method though.

Code: Select all

define "foo", 15;
divide foo, 5; //Returns 3
 
The idea is that everything that an operator can do, a method can do too. Sense users can define their own methods, and methods are the operators, then users are defineing operators so to speak, they're defining things on the lowest level of the language.

Re: Language concept.

Posted: Thu Sep 10, 2009 10:10 pm
by josh
Parenthesis are a more intuitive "grouping" paradigm to me.

Jquery earns money thru sponsors, corporate donations, and book sales.

.NET is an example of a for profit framework. You can make money off the IDEs, compilers, run-times, tools kinda like how Zend has byte-cache, zend server ( the error logger thingy), & code obfuscation ( for a fee )

Of course it may more conductive to ask what benefits this would provide over other languages, before asking how you are going to make money. Personally I think you are trying to take some of the bad features of javascript, not once did you mention concepts like lambda or closures that give javascript it's power, personally syntax is not one of javascript's virtues, it was originally intended to be a scheme like syntax but netscape made the inventor do last minute changes to a bracketed language, hence all the peculiarities about semicolon handling

Normally to get people to switch from their current ways of doing things you have to identify specific problems with the way they work, and then solve those problems, that creates a need for your product. Unfortunately I don't see why there would be a need for people to stop using parenthesis. Your way of grouping things with semi-colons reminds me BASIC with its IF, ELSE IF, END IF syntax, it forces me to scan back and forth instead of telling at a glance

http://en.wikipedia.org/wiki/Operator#O ... _functions
Operators versus functions

The word operator can in principle be applied to any function. However, in practice it is most often applied to functions which operate on mathematical entities of higher complexity than real numbers, such as vectors, random variables, or mathematical expressions. The differential and integral operators, for example, have domains and codomains whose elements are mathematical expressions of indefinite complexity. In contrast, functions with vector-valued domains but scalar ranges are called functionals and forms.

In general, if either the domain or codomain (or both) of a function contains elements significantly more complex than real numbers, that function is referred to as an operator. Conversely, if neither the domain nor the codomain of a function contain elements more complicated than real numbers, that function is likely to be referred to simply as a function. Trigonometric functions such as cosine are examples of the latter case.

Additionally, when functions are used so often that they have evolved faster or easier notations than the generic F(x,y,z,...) form, the resulting special forms are also called operators. Examples include infix operators such as addition "+" and division "/", and postfix operators such as factorial "!". This usage is unrelated to the complexity of the entities involved.
JellyFish wrote:. Sense users can define their own methods, and methods are the operators, then users are defineing operators so to speak, they're defining things on the lowest level of the language.
Technically not, id recommend to read up on lisp, sounds a lot like what you are trying to say
Lisp was the first homoiconic programming language: the primary representation of program code is the same type of list structure that is also used for the main data structures. As a result, Lisp functions can be manipulated, altered or even created within a Lisp program without extensive parsing or manipulation of binary machine code.
Although lambda would be a stepping stone before you got into that stuff, writing compilers is not easy I have heard ( from an ex Atari architect )

JellyFish wrote: As I analyse what a function is in most languages, I come to a conclusion. Functions are a block of code with a separate scrope, and that can be passed arguments and return a value. So I decided upon a simple syntax for create a function. I also decided that all functions should be first class citizens like in JavaScript, that is, make them a data type. So this is what I came up with for Dao:

Code: Select all

{
return "value";
};
In Dao, this is what is called a function literal. In other words the function is just a block of code, but is a data type like a string or number! This adds both block scope and function scope in Dao. Arguments are stored in a private array in Dao:
Just realized by this you probably are getting at the notion of closures and lambda. But note that those aren't the same concepts, your description kind of blurs the line between the concepts which I'm not sure I follow, how would I tell the compiler to "assign by value" rather then assigning "by behavior"

Re: Language concept.

Posted: Thu Sep 10, 2009 11:18 pm
by JellyFish
Thanks for your reply, josh. Which of JavaScript's bad features am I adopting? Also I'm not so sure what a lambda is, but I do know that these function blocks will be able to access variables defined within a parent function block (closures, no?).

What do you mean by "assign by value" and "by behavior"?

EDIT: Actually, from my research, a lambda is a function that can be passed as an argument to any other function. If my research is true, then I would say yes, that my functions are lambdas. Like I said in my last post, a function is nothing more then the following:
  • a block of code with separate scope.
  • returns a value when called.
  • is in fact a literal data type, like a string literal (which is basically a lambda).
  • can be assigned to a identifier (variable) passed as an argument (all because it's a literal data type).

Re: Language concept.

Posted: Fri Sep 11, 2009 2:18 am
by josh
JellyFish wrote:
What do you mean by "assign by value" and "by behavior"?
Also I'm not so sure what a lambda is
Yes this is lambda,

PHP assigns "by value" because the function is evaluated to a value which is passed,
javascript "assigns by behavior" because lambda involves passing the function itself which is a unit of behavior
JellyFish wrote:Which of JavaScript's bad features am I adopting?
JellyFish wrote:"The statement terminator operator not only ends the statement but is used as a delimiter too. It can act like a , (comma). "
In javascript there's lots of "quirks" for lack of a better word, just saying there shouldn't be conditional rules to memorize about such a basic language feature. For instance some of your changes involve rather trivial reasoning

"23.11; //How would the preprocessor know if 11 is a fractional value or a member of 23?", but then the whole conditional rules about the semi-colon usage offset any benefits gained from this, IMO
JellyFish wrote:, but I do know that these function blocks will be able to access variables defined within a parent function block (closures, no?).
Sorta, that is one part of closures

http://en.wikipedia.org/wiki/Closure_%2 ... science%29

read state representation, how it relates to first class functions, etc.. I think the biggest thing you left out was "A closure can be used to associate a function with a set of "private" variables, which persist over several invocations of the function. The scope of the variable encompasses only the closed-over function, so it cannot be accessed from other program code. "


I don't see why you aren't going to have operators either, I like my short hand, every line being a method call feels assembler or something

Re: Language concept.

Posted: Fri Sep 11, 2009 2:24 am
by josh
Think of lambda and closures kind of like the Strategy pattern on steroids, it IS the OOP model in javascript

Re: Language concept.

Posted: Fri Sep 11, 2009 11:47 am
by JellyFish
Sense I most likely would be interpreting this language in JavaScript, it would be very similar to how JavaScript treats functions. In fact the only difference is the syntax. I'm also going to be thinking about better ways to define public variables within these blocks.

Re: Language concept.

Posted: Sat Sep 12, 2009 11:55 am
by greyhoundcode
JellyFish wrote:I most likely would be interpreting this language in JavaScript
JellyFish wrote:Sorta like how Objective-J has it's own preprocessor, I'd might make one for Dao.
So would one write in Dao and have the script compiled into Javascript?

Re: Language concept.

Posted: Sat Sep 12, 2009 5:40 pm
by josh
So how would objects be handled? Would you have classes or would it be prototypical? What about control structures ( logical branching, loops )? Passing more arguments then a function accepts is already something you can do in a lot of languages, what about named parameters though, so they are not dependent on ordering?

Re: Language concept.

Posted: Sun Sep 13, 2009 1:57 am
by JellyFish
greyhoundcode: Yes I would have both a compiler and an interpreter that processes it into JavaScript.

As far as josh's questions. It would be prototypical. Loops would be built-in methods. Arguments can have labels:

Code: Select all

 
define "myFunc", {
return args/get "label";
};
myFunc label:"hello world";
//this way ordering can be anyway you like
define "person", {
define "name", args/name, "age", args/get "age"; //I think there should be two ways to get a element of an array
...
}
person age:23, name:"Bob"; //Is the same as...
person name:"Bob", age:23;