Phillip Trelford's Array

POKE 36879,255

C# Eye for the APL guy

A Programming Language (APL) was invented in the swinging 60s, first appearing in 1964. C#, an OOP language, first appeared in the year 2000, to coincide with Britney’s Oops!… I did it again world tour.

Adding numbers

APL C#
2 + 2
using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine(2 + 2);
    }    
}

 

Note: C# may get a REPL in Visual Studio when project Roslyn is finally released.

Min/Max

APL C#
11 ⌊ 20
75.6 ⌈ 87.3
11 28 52 14 ⌈ 20
Math.Min(11, 20);
Math.Max(75.6, 87.3);
(new[] { 11, 28, 52, 14 })
    .Select(x => Math.Min(x, 20));

Note: in C# math operations are preceded by Math and followed by dot.

Counting Costs

APL C#
Costs ← 10.4 11.5 10.8 24 16.9
+/ Costs
var costs = 
    new[] {10.4,11.5,10.8,24,16.9};
costs.Sum();

Computing Costs

APL C#

Price ← 5.2 11.5 3.6 4 8.45
Qty ← 2 1 3 6 2
Costs ← Price × Qty

var prices = 
    new[] {5.2,11.5,3.6,4,8.45};
var qtys =
    new[] {2,1,3,6,2};
var costs =
    prices
        .Zip(qtys, (price, qty) =>
        new {Price=price, Qty=qty})
        .Select(pair =>
        pair.Price * pair.Qty);

Summary

C# has the clear lead on the number of characters to express problems. That said if you’re not paid by the number of characters you write you may want to Try APL.

Comments (1) -

  • Martin Freedman

    4/1/2014 3:02:53 AM |

    Hilarious Phil!

    How about J versus F# that could be far more interesting

Comments are closed