All programming languages evolve towards Lisp

2007_01_28 120

In an internal DL people were debating what all should be included in the next version of C#. One of the things I suggested turned into an interesting thread.

Abhinaba: Add if as expression (like in Ruby) so that I can do the following

var ageGroup = if age < 2
               else if age < 19

SomeOne: Can’t we do

var ageGroup = ((age < 2) ? "Infant" : ((age < 19) ? "Teen" : String.Empty));

Abhinaba: We can but put 4 more cases and it’ll start looking like Lisp :) with all the parenthesis.

SomeTwo: All programming languages evolve towards Lisp.

Yeah, right!!!


Cross posted at my personal blog.

Comments (5)

  1. Ben says:

    The two code samples are semantically different.

    In the hypothetical if version, what is the value of ageGroup if age is, for example, 20? I would assume null. However, a variable of type var can not be set to null… You’d either have to either explicitly type it to be a String, and / or include an else block.

    In the ternary operator version, it becomes an empty string, different from the above version.

    Let me tell you what I want (and have been begging for since before Whidbey was released):

    1) Variance support. At least with interfaces to begin with. (A few good blogs about it recently.)

    2) Operator overloading in generic types. Need a way to declare that a type implements a specific operator (which happens to be static!).

    3) There is no way to know what types are addable, subtractable etc. Create an IAdd, ISubtract, IMultiply etc and apply them to the base types as appropriate.

    Implement nothing but these and I will be extremely happy.

  2. oldnewthing says:

    And you don’t need parentheses to use the ternary. A little line breaking and indenting and it’s pretty straightforwardly readable as a chain of "if" statements.

    var ageGroup = age < 2 ? "Infant"

    : age < 19 ? "Teen"

    : String.Empty;

  3. mfp says:

    It’s evolving towards F#; in other words, towards OCaml and ML (some will argue that the latter is Lispish in nature, though).

  4. leppie says:

    (define age-group


      ((< age 2) "Infant")

      ((< age 19) "Teen")))

  5. Joe Chung says:

    Hmm, I wonder what LISP would look like with significant whitespace instead of parentheses…