The code may look like natural language, but it is really just regular computer code with different keywords. In your example, I want
is probably somewhat synonymous with new
. It's not like you can use natural language directly and say make me a window
instead (and if you could do that, things would get even uglier...).
Lets take a close look at your code and the language implications:
i want window and the window title is Hello World.
i want
is unnecessarily verbose for new
, and
denotes beginning of the argument list. the <typename> <member_name> is
sets instance variable member_name on object being created.
i want button and button caption is Close.
and button name is btn1.
.
ends statement. continuation of an argument list can happen in a new statement starting with and
. button caption
is syntactic sugar for button.caption
btn1 mouse click. instructions are
you close window
end of instructions
mouse click
is a keyword containing a space, should be mouseClick
. instructions are
defines a lambda (see the is
vs. are
keyword confusion causing trouble yet?). you close window
calls function window.close()
. end of instructions
is end of a lambda. All of these are far longer than they need to be.
Remember all that? And that's only my guesses at the syntax, many of why are probably wrong. Still seem simple? If so, try writing a larger program without breaking any of those rules.
Try this translation:
var myWindow = new Window( title="Hello World" );
myWindow.addButton( new Button( caption="close", name="btn1" ) );
btn1.onMouseClick = function() {
myWindows.close();
}
See how each line maps to its counterpart in the previous example, but states the intent for more succinctly? Natural language may be good for execution by humans, but it is terribly difficult to group into a precise specification. :D