comp.lang.ada
 help / color / mirror / Atom feed
* Lambda expressions? LINQ?
@ 2009-09-16  2:23 Steve D
  2009-09-16  8:03 ` Georg Bauhaus
  2009-09-16 10:46 ` Jeffrey R. Carter
  0 siblings, 2 replies; 12+ messages in thread
From: Steve D @ 2009-09-16  2:23 UTC (permalink / raw)


I've been doing some c# programming and have just started using LINQ 
(language integrated query).

Using LINQ and the .NET framework I was able to query an XML document for 
all elements with a given element name, select an attribute with a specific 
name, split the content of the attribute (a comma separated list of strings) 
into it's individual strings and return an array of unique elements... in 
one line of source code.  When it worked after less than a minute of 
fiddling I sat back and said... Wow!

Anything under way to make this kind of power available in Ada (outside of 
A#)?

Regards,
Steve 




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Lambda expressions? LINQ?
  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
  1 sibling, 0 replies; 12+ messages in thread
From: Georg Bauhaus @ 2009-09-16  8:03 UTC (permalink / raw)


Steve D wrote:
> I've been doing some c# programming and have just started using LINQ
> (language integrated query).
> 
> Using LINQ

Not trouble free for building into Ada or libraries, I guess,
http://www.faqs.org/patents/app/20090144229

> and the .NET framework I was able to query an XML document
> for all elements with a given element name,

Would this help?
http://www.mckae.com/xia.html


> Anything under way to make this kind of power available in Ada (outside
> of A#)?

All it takes is writing an additional translator into
a number of compilers and provide .NET like objects
for the background processing of queries. :-)



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Lambda expressions? LINQ?
  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  7:58   ` Martin
  1 sibling, 2 replies; 12+ messages in thread
From: Jeffrey R. Carter @ 2009-09-16 10:46 UTC (permalink / raw)


Steve D wrote:
> 
> Using LINQ and the .NET framework I was able to query an XML document 
> for all elements with a given element name, select an attribute with a 
> specific name, split the content of the attribute (a comma separated 
> list of strings) into it's individual strings and return an array of 
> unique elements... in one line of source code. ... Wow!

Sounds like a write-only language to me.

-- 
Jeff Carter
"My dear Mrs. Hemoglobin, when I first saw you, I
was so enamored with your beauty I ran to the basket,
jumped in, went down to the city, and bought myself a
wedding outfit."
Never Give a Sucker an Even Break
111



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Lambda expressions? LINQ?
  2009-09-16 10:46 ` Jeffrey R. Carter
@ 2009-09-18  1:59   ` Steve D
  2009-09-18  5:23     ` sjw
  2009-09-18 13:42     ` Jeffrey R. Carter
  2009-09-18  7:58   ` Martin
  1 sibling, 2 replies; 12+ messages in thread
From: Steve D @ 2009-09-18  1:59 UTC (permalink / raw)


"Jeffrey R. Carter" <spam.jrcarter.not@spam.acm.org> wrote in message 
news:h8qf72$jv2$2@news.tornevall.net...
> Steve D wrote:
>>
>> Using LINQ and the .NET framework I was able to query an XML document for 
>> all elements with a given element name, select an attribute with a 
>> specific name, split the content of the attribute (a comma separated list 
>> of strings) into it's individual strings and return an array of unique 
>> elements... in one line of source code. ... Wow!
>
> Sounds like a write-only language to me.
>

Oh, so you are familiar with LINQ and find that you cannot make queries that 
are readable?
My experience is not the same.

Or are you passing judgment without knowledge in the same way that most 
people do when I argue for using Ada?

Regards,
Steve

> -- 
> Jeff Carter
> "My dear Mrs. Hemoglobin, when I first saw you, I
> was so enamored with your beauty I ran to the basket,
> jumped in, went down to the city, and bought myself a
> wedding outfit."
> Never Give a Sucker an Even Break
> 111





^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Lambda expressions? LINQ?
  2009-09-18  1:59   ` Steve D
@ 2009-09-18  5:23     ` sjw
  2009-09-19  2:33       ` Steve D
  2009-09-18 13:42     ` Jeffrey R. Carter
  1 sibling, 1 reply; 12+ messages in thread
From: sjw @ 2009-09-18  5:23 UTC (permalink / raw)


On Sep 18, 2:59 am, "Steve D" <nospam_steve...@comcast.net> wrote:
> "Jeffrey R. Carter" <spam.jrcarter....@spam.acm.org> wrote in messagenews:h8qf72$jv2$2@news.tornevall.net...
>
> > Steve D wrote:
>
> >> Using LINQ and the .NET framework I was able to query an XML document for
> >> all elements with a given element name, select an attribute with a
> >> specific name, split the content of the attribute (a comma separated list
> >> of strings) into it's individual strings and return an array of unique
> >> elements... in one line of source code. ... Wow!
>
> > Sounds like a write-only language to me.
>
> Oh, so you are familiar with LINQ and find that you cannot make queries that
> are readable?
> My experience is not the same.

It would certainly be interesting to see this one-liner (or even an
approximation to it!).



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Lambda expressions? LINQ?
  2009-09-16 10:46 ` Jeffrey R. Carter
  2009-09-18  1:59   ` Steve D
@ 2009-09-18  7:58   ` Martin
  1 sibling, 0 replies; 12+ messages in thread
From: Martin @ 2009-09-18  7:58 UTC (permalink / raw)


On Sep 16, 11:46 am, "Jeffrey R. Carter"
<spam.jrcarter....@spam.acm.org> wrote:
> Steve D wrote:
>
> > Using LINQ and the .NET framework I was able to query an XML document
> > for all elements with a given element name, select an attribute with a
> > specific name, split the content of the attribute (a comma separated
> > list of strings) into it's individual strings and return an array of
> > unique elements... in one line of source code. ... Wow!
>
> Sounds like a write-only language to me.
>
> --
> Jeff Carter
> "My dear Mrs. Hemoglobin, when I first saw you, I
> was so enamored with your beauty I ran to the basket,
> jumped in, went down to the city, and bought myself a
> wedding outfit."
> Never Give a Sucker an Even Break
> 111

No, no - it just looks like SQL! Very readable - even for non-SQLers.
It's been >15 years since I did /any/ DB work and I manage to follow
LINQ (in C# - a language I don't know) quite easily.

Cheers
-- Martin

p.s. some examples at: http://msdn.microsoft.com/en-us/vcsharp/aa336758.aspx




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Lambda expressions? LINQ?
  2009-09-18  1:59   ` Steve D
  2009-09-18  5:23     ` sjw
@ 2009-09-18 13:42     ` Jeffrey R. Carter
  2009-09-18 15:45       ` Martin
  1 sibling, 1 reply; 12+ messages in thread
From: Jeffrey R. Carter @ 2009-09-18 13:42 UTC (permalink / raw)


Steve D wrote:
> 
> Oh, so you are familiar with LINQ and find that you cannot make queries 
> that are readable?
> My experience is not the same.
> 
> Or are you passing judgment without knowledge in the same way that most 
> people do when I argue for using Ada?

None of the above. I am simply saying that the description (a single line of 
source code that does many things) sounds to me very similar to descriptions of 
write-only languages.

-- 
Jeff Carter
"Have you gone berserk? Can't you see that that man is a ni?"
Blazing Saddles
38



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Lambda expressions? LINQ?
  2009-09-18 13:42     ` Jeffrey R. Carter
@ 2009-09-18 15:45       ` Martin
  0 siblings, 0 replies; 12+ messages in thread
From: Martin @ 2009-09-18 15:45 UTC (permalink / raw)


On Sep 18, 2:42 pm, "Jeffrey R. Carter"
<spam.jrcarter....@spam.acm.org> wrote:
> Steve D wrote:
>
> > Oh, so you are familiar with LINQ and find that you cannot make queries
> > that are readable?
> > My experience is not the same.
>
> > Or are you passing judgment without knowledge in the same way that most
> > people do when I argue for using Ada?
>
> None of the above. I am simply saying that the description (a single line of
> source code that does many things) sounds to me very similar to descriptions of
> write-only languages.
>
> --
> Jeff Carter
> "Have you gone berserk? Can't you see that that man is a ni?"
> Blazing Saddles
> 38


My guess is that it'll be 1 statement spread over many lines...

Cheers
-- Martin



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Lambda expressions? LINQ?
  2009-09-18  5:23     ` sjw
@ 2009-09-19  2:33       ` Steve D
  2009-09-19  6:50         ` Martin
  0 siblings, 1 reply; 12+ messages in thread
From: Steve D @ 2009-09-19  2:33 UTC (permalink / raw)


>"sjw" <simon.j.wright@mac.com> wrote in message 
>news:9b330aae-2c83-4d1c-995b-192425cd1c52@m11g2000vbl.googlegroups.com...
>On Sep 18, 2:59 am, "Steve D" <nospam_steve...@comcast.net> wrote:
>> "Jeffrey R. Carter" <spam.jrcarter....@spam.acm.org> wrote in 
>> messagenews:h8qf72$jv2$2@news.tornevall.net...
>>
>> > Steve D wrote:
>>
>> >> Using LINQ and the .NET framework I was able to query an XML document 
>> >> for
>> >> all elements with a given element name, select an attribute with a
>>> >> specific name, split the content of the attribute (a comma separated 
>>> >> list
>> >> of strings) into it's individual strings and return an array of unique
>> >> elements... in one line of source code. ... Wow!
>>
>> > Sounds like a write-only language to me.
>>
>> Oh, so you are familiar with LINQ and find that you cannot make queries 
>> that
>> are readable?
>> My experience is not the same.
>
>It would certainly be interesting to see this one-liner (or even an
>approximation to it!).

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();

There is an alternate way of formatting the query... more like SQL, but I 
prefer the version that uses the dot notation.

Here's a small chunk of the XML data it is reading:

<File>
  <!-- Message #1 -->
  <NewMessage>
    <Time>10:08:19.812</Time>
    <Layer0Message Type="2000" Name="MAL_RAW_ENCODER" From="encoder" To=" 
sequencer, turnset" OriginalBytes="12" SavedBytes="12" DataFormat="INT8 HEX" 
/>
    <Data>63 BF F4 C0 C7 3C 02 00 C3 4F 4F 14 </Data>
  </NewMessage>
  <!-- Message #2 -->
  <NewMessage>
    <Time>10:08:19.812</Time>
    <Layer0Message Type="2210" Name="ROTATION_MEASUREMENT" From="rda" To=" 
turnset" OriginalBytes="6" SavedBytes="6" DataFormat="INT8 HEX" />
    <Data>88 3D 5A C2 32 BD </Data>
  </NewMessage>


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.

Regards,
Steve 




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Lambda expressions? LINQ?
  2009-09-19  2:33       ` Steve D
@ 2009-09-19  6:50         ` Martin
  2009-09-19 14:35           ` Brad Moore
  0 siblings, 1 reply; 12+ messages in thread
From: Martin @ 2009-09-19  6:50 UTC (permalink / raw)


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();
>
> There is an alternate way of formatting the query... more like SQL, but I
> prefer the version that uses the dot notation.

I'd prefer the other way myself :-)

Could you perhaps post 'the other way' for a comparison?


[snip]
> I just wish my favoriate language had this feature.

Me too - although I can't see how it could be :-(

Cheers
-- Martin



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Lambda expressions? LINQ?
  2009-09-19  6:50         ` Martin
@ 2009-09-19 14:35           ` Brad Moore
  2009-09-19 16:38             ` Martin
  0 siblings, 1 reply; 12+ messages in thread
From: Brad Moore @ 2009-09-19 14:35 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Lambda expressions? LINQ?
  2009-09-19 14:35           ` Brad Moore
@ 2009-09-19 16:38             ` Martin
  0 siblings, 0 replies; 12+ messages in thread
From: Martin @ 2009-09-19 16:38 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2009-09-19 16:38 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2009-09-18 13:42     ` Jeffrey R. Carter
2009-09-18 15:45       ` Martin
2009-09-18  7:58   ` Martin

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