comp.lang.ada
 help / color / mirror / Atom feed
From: Martin <martin.dowie@btopenworld.com>
Subject: Re: Lambda expressions? LINQ?
Date: Sat, 19 Sep 2009 09:38:26 -0700 (PDT)
Date: 2009-09-19T09:38:26-07:00	[thread overview]
Message-ID: <415ed6b3-2a97-46da-95f0-179632c64b91@j19g2000vbp.googlegroups.com> (raw)
In-Reply-To: z_5tm.58012$4t6.57033@newsfe06.iad

On Sep 19, 3:35 pm, Brad Moore <brad.mo...@shaw.ca> wrote:
> Martin wrote:
> > On Sep 19, 3:33 am, "Steve D" <nospam_steve...@comcast.net> wrote:
> > [snip]
> >> As Martin guessed it is one statement spread over a few lines.
>
> >>             string[] names = xDoc.Descendants("Layer0Message")
> >>                               .SelectMany(node =>
> >> node.Attribute("To").Value.Split(' ',',').Where( st => st.Length > 0 ))
> >>                                   .Distinct().OrderBy(n=>n).ToArray();
>
> >> Oh, and by the way.  LINQ isn't just for XML.  You can do queries on arrays,
>
>  >> lists, etc.  For example if you have an array of records you can do a
>  >> query to select all of the records with a field that has a particular
>  >> value. It's cool.
>
> >> I just wish my favoriate language had this feature.
>
> > Me too - although I can't see how it could be :-(
>
> I'm not sure I see why this couldn't be.
> At first glance, the code fragment looks a lot like Ada.
>
> If existing packages (such as XML/Ada see
> (http://libre.adacore.com/libre/tools/xmlada/) do not already
> have this capability, then why couldn't someone write such a package in
> Ada? I don't see the language being a barrier here.
> Ada.Containers.Vectors for example lets you query an array of records to
> select all the records with a field that has a particular value.
>
> What is missing?
>
> Brad

Well, perhaps you could using the dot notation as above but the real
value of LINQ to me is the sql like syntax that you can see in
examples, such as those on the MS site, e.g.

public void Linq11() {
    List products = GetProductList();

    var productInfos =
        from p in products
        select new {p.ProductName, p.Category, Price = p.UnitPrice};

    Console.WriteLine("Product Info:");
    foreach (var productInfo in productInfos) {
        Console.WriteLine("{0} is in the category {1} and costs {2}
per unit.", productInfo.ProductName, productInfo.Category,
productInfo.Price);
    }
}

Check that 'select new {' line...very SQL! Even to my Ada-eyes a 'dot
notation' version just isn't as readable.

Cheers
-- Martin



  reply	other threads:[~2009-09-19 16:38 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-16  2:23 Lambda expressions? LINQ? Steve D
2009-09-16  8:03 ` Georg Bauhaus
2009-09-16 10:46 ` Jeffrey R. Carter
2009-09-18  1:59   ` Steve D
2009-09-18  5:23     ` sjw
2009-09-19  2:33       ` Steve D
2009-09-19  6:50         ` Martin
2009-09-19 14:35           ` Brad Moore
2009-09-19 16:38             ` Martin [this message]
2009-09-18 13:42     ` Jeffrey R. Carter
2009-09-18 15:45       ` Martin
2009-09-18  7:58   ` Martin
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox