This is a post about my dream language, which I've named CargoCult. It's a mashup of Perl, Objective-C, JavaScript, Shell, and other things.
It does NOT eschew the use of shifted characters -- it just requires that they be important, with a value greater than the extra effort of typing shift + something.
Object Notation
CargoCult is a dynamic object language. This means you have type-able structures, potentially dynamic, which have attributes and methods.
Core language features -- arrays, hashes, variables -- are objects. For example, the implicit array type is an object, so you can do things like this:
return [d1, d2, d3].sort.reverse.pop;
Hashes and arrays use the grouping notation of braces. An array is a comma-separated list of scalars. A hash is a comma-separated list of assignments.
my array = 1, 2, 3, 'four'; # also [ 1, 2, 3, 'four' ]
my hash = [year = 2012, month = two, day = 23];
Hash and array accesses are object calls.
my value = hash.year;
my other_value = array.0;
my other_value = array.0;
Method Calling with Parameters
When we write methods in any language, we typically name formal parameters. For example:
string myFunction( foo, bar )
{
foo + ': ' + bar;
}
foo and bar are formal parameters, i.e. the names used in the method.
When calling a method, parameters are passed in by name. In other words, the parameters are more or less a hash.
my str = myObj myFunction .foo 'hello' .bar 'world';
When you have to nest the call, use the backslash to indicate a method call (rather than a new array), and then braces for grouping.
my str = myObj myFunction .foo \[myObj myFunction .foo 'hello' .bar 'world'] .bar '!';
No comments:
Post a Comment