Skip to content

My Programming Language (Delphi) Can Do This

joelonsoftware asks on his blog "Can Your Programming Language Do This?". Delphi 2009 introduces support for anonymous methods in Delphi language. Yes, Delphi can do this:-)

For your convinience here is the relevant snippet from Joel’s blog:


Delphi, contrary to JavaScript, is a strongly-typed language. This is the reason you need to define an anonymous method signature.  I think it is a good thing.

Here is the output from a simple console application:

I have my private theory about Joel’s lastname which is "Spolsky". I’m Polish myself and I guees there is some Polish connection here. "Spolsky" sounds like "z Polski" in Polish language, which is "from Poland" but just made more English-looking like.

And make sure you visit "Stack Overflow" for ultimate programmers’ FAQ system.
Creating an account on Stack Overflow is tricky. I had to create a blog account on blogspot server to obtain an openID.

Delphi 2009 and C++Builder 2009 introduce full Unicode support. Here is "The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)".

{ 6 } Comments

  1. Kryvich | September 21, 2008 at 7:58 pm | Permalink

    Apparently you can write it as
    procedure Cook(s1, s2: string; p: TProc);

    No declaration of the anonymous method is needed.

  2. Kryvich | September 21, 2008 at 8:02 pm | Permalink

    Ooops, the brackets have disappeared.

    Should be
    procedure Cook(s1, s2: string; p: TProc LEFT_ANGLE String RIGHT_ANGLE );

  3. Jolyon Smith | September 22, 2008 at 11:34 am | Permalink

    Indeed, I think Pawel somewhat missed the point of Joel’s article.

    When Joel asks "Can your language do this?" he wasn’t asking "Does your language have anonymous methods?". He was referring to using functions as things that can be passed around, e.g. to be invoked later/elsewhere.

    Some languages cannot do this and *need* anonymous methods.

    Delphi didn’t have anonymous methods before Delphi 2009, but has always had "first class functions". Users of Delphi 1.0 would have answered "Yes" to Joel’s question.

    Anonymous methods do of course add more, in the form of more flexible and, some would say, powerful closures, but these are potentially also far more confusing (for the poor old human reader, not the compiler).

  4. Jolyon Smith | September 22, 2008 at 11:44 am | Permalink

    For completeness:

    TCookingProc = procedure(aIngredient: String);

    procedure Potted(aIngredient: String);
    WriteLn(’Pot ‘ + aIngredient);

    procedure Boomed(aIngredient: String);
    WriteLn(’Boom ‘ + aIngredient);

    procedure Cook(aFirst, aSecond: String; aProc: TCookingProc);
    WriteLn(’Get the ‘ + aFirst);

    procedure DoCooking;
    Cook(’lobster’, ‘water’, Potted);
    Cook(’chicken’, ‘coconut’, Boomed);

    (not tested - not even compiled. These comment editors don’t make very good IDE’s - lol)

  5. Stefaan Lesage | September 22, 2008 at 12:08 pm | Permalink

    Nice piece of code. I didn’t even know that was possible :-)

    Regards from Belgium,


  6. Michael Madsen | September 23, 2008 at 3:38 pm | Permalink

    Actually, Joel does mention that he wants to be able to declare the function in-line (there’s a comment about function pointers in C, where he mentions the whole "having to declare the function elsewhere" as being a bit of a burden) - so he *does* actually ask for anonymous methods.

Post a Comment

Your email is never published nor shared. Required fields are marked *

Bad Behavior has blocked 2 access attempts in the last 7 days.