ebooksgratis.com

See also ebooksgratis.com: no banners, no cookies, totally FREE.

CLASSICISTRANIERI HOME PAGE - YOUTUBE CHANNEL
Privacy Policy Cookie Policy Terms and Conditions
Cola (programming language) - Wikipedia, the free encyclopedia

Cola (programming language)

From Wikipedia, the free encyclopedia

Cola is a programming language similar to Java and C# with some higher level features of Perl and Ruby including first-class regular expressions. It can be compiled for the Microsoft .NET CLR or the Parrot virtual machine.

Cola is a compiled language with static type checking, but the designer mixed in some of the features more common to powerful scripting languages like Perl and Ruby. According to the author, after years of using Java and C++ for large projects, and Perl for small to medium ones, there seemed to be no language to fill the gap. Cola is less of a new language "design" than a mix of several very powerful languages with the following key principles in mind:

Curly braces and semi-colons at the heart - Java and Perl programmers should both be comfortable, whitespace has no effect on the semantics.

Convention over Code - Things that are conventional don't need to be explicit (Java/C# public keyword on methods)

Low signal-to-noise ratio - Use Convention over Code to reduce keyword clutter and improve readability. Don't clutter the expression of an idea with implementation of the idea. Java and C# exhibit this in what many consider poor choice of default scope access of fields and methods. In practice, the use of the word public dominates Java and C# syntax.

Strings and text processing are top priority - Most programming involves strings and text manipulation. Supporting regular expression dramatically increases the power of a language, but BUILTIN syntax for regular expressions improves the readability. When combined, they increase the productivity of the programmer.

Scriptlets should be possible - No default class with a static main required just to do a small job.

A Hello world program written in Cola three ways:

// C/Perl-style without classes
// Cola package/global methods are static by default, void by default

string mesg = "Hello world\n";
main() {
   print(mesg);
}
// Cola OO-style
// classes, methods and constructors public by default, fields private by default
class Hello {
   string mesg;
   new() { mesg = "Hello world\n"; }
   static void main() {
       print(mesg);
   }
}
// Cola (C#/Java "explicit wordy" style)
// Note scope resolution begins a typical declaration. This style is
// avaialable but discouraged in Cola
public class Hello {
   private string mesg;
   public new() { mesg = "Hello world\n"; }
   public static void main() {
       print(mesg);
   }
}

In the examples above, it is nearly possible to write Java in Cola, but not Cola in Java.

An example of Cola's support for regular expression and matching is given below. First a conventional example that echoes Perl's approach.

// implicit match backreference
if(mesg =~ /(yes)(madam)/) {
   print("In string: " + $0);
   print("we matched: " + $1 + ", " + $2);
}

Cola includes a more powerful, expressive notation for matching called match aliasing. Simply put, any match expression can declare an object of type match as part of the expression (similar to the spirit of declaring a named iterator with C++ or Java in a for loop: for(int i = 0; i < 100; i++)

// explicit named match example
if("foobar" =~ /foo(bar)/ as match1) {
   // default is matchA
   print(match1.$1);
}

For the scope of the if statement, match1 is in scope and can be used for clarity. The advantage to match aliasing is more evident when we have multiple, nested matches.

if("foobar" =~ /foo(bar)/ as match1) {
   // We can use a backreference in a new match expression
   // $1 refers to match1 until a new match expression, after which
   // it refers to the new match in immediate scope. To refer back
   // we use match1 alias (match1.$1)
   if($1 =~ /b(ar)/ as match2) {
      print(match1.$1);    // match1 still in scope
      print(match2.$1);    // match2 now in scope, and the default
      print($1);           // same as match2.$1
   }
} 

Cola also includes foreach() iteration, and currently works for the builtin .NET non-generic types in System.Collections. Cola foreach() is implemented similar to the C# compiler, generating code to use the IEnumerable interface, or to check for the proper enumeration signature on the underlying container.

  // Uses .NET System.Collections
  System.Collections.ArrayList list = new;   // note the inferred type for new
  list.Add("LITTLEDOG");
  list.Add("BIGDOG");
  list.Add("LITTLECAT");
  list.Add("BIGCAT");
  foreach(string s in list) {
     // Nested named matching
     if(s =~ /(LITTLE|BIG)/ as size) {
        if(s =~ /(DOG|CAT)/ as animal)
           print("Animal is a " + size.$1 + " " + animal.$1);
     }
  }

A current alpha version of the Cola compiler for .NET is available via email from the author (Melvin Smith), see *[1] or email <cola @ itechdata.com>

[edit] External links

[edit] See also


aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -