Talk:А ваш язык программирования так может?

From The Joel on Software Translation Project

Jump to: navigation, search

Конечно может :) http://tbpl.info/

  function Cook( i1, i2, f )
  {
     alert("get the " + i1);
     f(i1);
     f(i2);
  }
  Cook( "lobster", "water", PutInPot );
  Cook( "chicken", "coconut", BoomBoom );
  Cook( "lobster",
        "water",
        function(x) { alert("pot " + x); }  );
  Cook( "chicken",
        "coconut",
        function(x) { alert("boom " + x); } );
  map( function(x){return x*2;}, a );
  map( alert, a );
  function sum(a)
  {
      var s = 0;
      for (i = 0; i < a.length; i++)
          s += a[i];
      return s;
  }
  function join(a)
  {
      var s = "";
      for (i = 0; i < a.length; i++)
          s += a[i];
      return s;
  }
  alert(sum([1,2,3]));
  alert(join(["a","b","c"]));
  function reduce(fn, a, init)
  {
      var s = init;
      for (i = 0; i < a.length; i++)
          s = fn( s, a[i] );
      return s;
  }

 'Cook =
 {
   io <<< "get the \{i1}";
   f(i1);
   f(i2);
 };
 :Cook $i1 -> $lobster, $i2 -> $water, $f -> &PutInPot;
 :Cook $i1 -> $chicken, $i2 -> $coconut, $f -> &BoomBoom;
 :Cook $i1 -> $lobster, $i2 -> $water, $f -> { io <<< "pot \{|x|}"; };
 :Cook $i1 -> $chicken, $i2 -> $coconut, $f -> { io <<< "boom \{|x|}"; };
 a map! { |x| * 2 };
 a each { io <<< |x|; };
 'sum =:
 {
   's = 0;
   |arr| each { s += |x|; };
   s
 } 'rassoc;
 io <<< sum [1,2,3];
 io <<< [$a,$b,$c] toString;
 'reduce =
 {
   's = init;
   |arr| each { f: |x|; };
   s
 };
 io <<< reduce([1,2,3], $f -> { s += |x| }, $init -> 0);

Personal tools