473,326 Members | 2,182 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Problems compiling a lambda expression

I've got a hint from a gentleman here to use the
following syntax.

public static FileInfo[]
GetFilesRegExp(this DirectoryInfo di, string pat)
{
Regex re = new Regex(pat);
return Array.FindAll(
di.GetFiles(),
(f) =re.IsMatch(f.Name));
}

The problem is that the compiler seems to dislike
"this" in the argument list as well as "goes to"
in the lambda expression.

What's up with that and how do i kill it?

--
Regards
Konrad Viltersten
----------------------------------------
May all spammers die an agonizing death;
have no burial places; their souls be
chased by demons in Gehenna from one room
to another for all eternity and beyond.
Jul 26 '08 #1
15 4443
On Sat, 26 Jul 2008 10:39:17 -0700, K Viltersten <tm**@viltersten.com>
wrote:
I've got a hint from a gentleman here to use the
following syntax.

public static FileInfo[]
GetFilesRegExp(this DirectoryInfo di, string pat)
{
Regex re = new Regex(pat);
return Array.FindAll(
di.GetFiles(),
(f) =re.IsMatch(f.Name));
}

The problem is that the compiler seems to dislike
"this" in the argument list as well as "goes to"
in the lambda expression.

What's up with that and how do i kill it?
What errors are you getting _exactly_. Writing "the compiler seems to
dislike" doesn't explain your problem at all.

As far as the "this", I expect that either you're not using C# 3.0 or
you're trying to declare the method in a non-static class. But without
knowing the error, it's hard to say for sure which or whether either is
correct.

I don't see anything obviously wrong with the lambda expression, but
again...if you're not using C# 3.0, then it wouldn't work.

Knowing the actual error message would help a _lot_. Frankly, that's
always going to be true if you are asking about help with errors that
occur, either during compilation or execution.

Pete
Jul 26 '08 #2
>The problem is that the compiler seems to dislike
>"this" in the argument list as well as "goes to"
in the lambda expression.

What's up with that and how do i kill it?

What errors are you getting _exactly_. Writing "the compiler seems to
dislike" doesn't explain your problem at all.

As far as the "this", I expect that either you're not using C# 3.0 or
you're trying to declare the method in a non-static class. But without
knowing the error, it's hard to say for sure which or whether either is
correct.

I don't see anything obviously wrong with the lambda expression, but
again...if you're not using C# 3.0, then it wouldn't work.

Knowing the actual error message would help a _lot_. Frankly, that's
always going to be true if you are asking about help with errors that
occur, either during compilation or execution.
I could argue that i provided just enough information, my
helpful friend. In fact, i was using v2.0, which i wasn't
aware of until you pointed it out. Thanks a million!

(Of course, i agree with you - one should almost always
provide the error messages. In this case, i KNEW it
couldn't be that. However, for future reference, i'll do it.)

Now, i was sure that installing VS 2008 upgraded my
framework to v3.5. Obviously, it didn't... Is the upgrade
to the latest version of the framework free of charge if
i'm already on a paid version of VS2005?

--
Regards
Konrad Viltersten
----------------------------------------
May all spammers die an agonizing death;
have no burial places; their souls be
chased by demons in Gehenna from one room
to another for all eternity and beyond.
Jul 26 '08 #3
On Sat, 26 Jul 2008 11:08:15 -0700, K Viltersten <tm**@viltersten.com>
wrote:
[...]
>Knowing the actual error message would help a _lot_. Frankly, that's
always going to be true if you are asking about help with errors that
occur, either during compilation or execution.

I could argue that i provided just enough information, my
helpful friend.
Well, you can argue anything you like. That doesn't mean you'd be right.
:)
In fact, i was using v2.0, which i wasn't
aware of until you pointed it out. Thanks a million!
C# 2.0? Or .NET 2.0?
(Of course, i agree with you - one should almost always
provide the error messages. In this case, i KNEW it
couldn't be that. However, for future reference, i'll do it.)

Now, i was sure that installing VS 2008 upgraded my
framework to v3.5. Obviously, it didn't... Is the upgrade
to the latest version of the framework free of charge if
i'm already on a paid version of VS2005?
If you're using VS 2008, you're using C# 3.0. In VS 2008, projects can
target any specific version of .NET from 2.0 on. The default ought to be
..NET 3.5, but the issues you're asking about are language/compiler issues
so even if you accidently targeted an earlier version of .NET, using VS
2008 should still allow it to compile. Conversely, just having the .NET
3.5 SDK installed isn't sufficient. You need to be using the compiler
that supports C# 3.0 features, which is VS 2008.

In other words, we're back to my previous comment: without knowing the
exact error message, it's impossible to say for sure what the problem is.

_If_ my comments about language version have led you to an actual
solution, then _maybe_ you can try to argue that you've provided enough
information (but I'll just argue I'm a good guesser :) ). But if you
haven't solved the problem yet even with the answer I've given so far,
obviously you haven't provided enough information to answer the question
yet. :)

Pete
Jul 26 '08 #4
>Now, i was sure that installing VS 2008 upgraded my
>framework to v3.5. Obviously, it didn't... Is the upgrade
to the latest version of the framework free of charge if
i'm already on a paid version of VS2005?

If you're using VS 2008, you're using C# 3.0. In VS 2008, projects can
target any specific version of .NET from 2.0 on. The default ought to be
.NET 3.5, but the issues you're asking about are language/compiler issues
so even if you accidently targeted an earlier version of .NET, using VS
2008 should still allow it to compile. Conversely, just having the .NET
3.5 SDK installed isn't sufficient. You need to be using the compiler
that supports C# 3.0 features, which is VS 2008.

In other words, we're back to my previous comment: without knowing the
exact error message, it's impossible to say for sure what the problem is.
First of all - thanks for help. It's needed and apreciated!

Secondly, this is the stuation on my computer today.
VS2005, v8.0
DotNet framework v2.0
MS VC# 2005
According to the lis tin the control panel, i have a bunch of frameworks
installed: v1.1, v.2.0, v3.5 and so on.

The error message i perhaps should have provided is as follows.
Error 3 Invalid expression term '>'
C:\dev\dummies\XMLReading01.cs 36 24 DummySpace

The two lines causing the problems are as follows.
int[] arr = new int[] { 1, 13, 5, 3, 12, 1, -3, 4 };
arr.Average((numb) =numb 4);

--
Regards
Konrad Viltersten
----------------------------------------
May all spammers die an agonizing death;
have no burial places; their souls be
chased by demons in Gehenna from one room
to another for all eternity and beyond.

Jul 26 '08 #5
On Sat, 26 Jul 2008 11:37:59 -0700, K Viltersten <tm**@viltersten.com>
wrote:
[...]
Secondly, this is the stuation on my computer today.
VS2005, v8.0
This is your problem.
DotNet framework v2.0
MS VC# 2005
According to the lis tin the control panel, i have a bunch of frameworks
installed: v1.1, v.2.0, v3.5 and so on.
As I wrote, the .NET version doesn't help. You have to be using the right
compiler, and the 2005 version of the C# compiler isn't the right one. It
only supports C# 2.0.

You can either revert to the older "delegate" syntax (so "(f) =>
re.IsMatch(f.Name)" becomes "delegate (string f) { return
re.IsMatch(f.Name); }"), or you can switch to the newer compiler (the most
obvious way would be to just use the 2008 version of VS, either Visual C#
Express 2008 or the retail version of Visual Studio 2008).

As far as the extension method you tried to declare, there is no C# 2.0
equivalent. If you can't or won't upgrade your compiler, you'll just have
to call the static method explicitly, and declare it without the "this" in
the parameter list.

Pete
Jul 26 '08 #6
K Viltersten <tm**@viltersten.comwrote:
First of all - thanks for help. It's needed and apreciated!

Secondly, this is the stuation on my computer today.
VS2005, v8.0
DotNet framework v2.0
MS VC# 2005
According to the lis tin the control panel, i have a bunch of frameworks
installed: v1.1, v.2.0, v3.5 and so on.

The error message i perhaps should have provided is as follows.
Error 3 Invalid expression term '>'
C:\dev\dummies\XMLReading01.cs 36 24 DummySpace

The two lines causing the problems are as follows.
int[] arr = new int[] { 1, 13, 5, 3, 12, 1, -3, 4 };
arr.Average((numb) =numb 4);
And what are you building with? The command line? Visual Studio? If
you're building with the command line, you need to make sure you're
using one with the correct environment variables set up.

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Jul 26 '08 #7
<snip>
If you've got .NET 3.5 installed, you've got the C# 3.0 compiler
installed - but you can't make VS 2005 use it. So you could build C# 3
code from the command line, but not from VS 2005.
I'll consider it. It'll be like in the good old
days, when i could type:
javac Main.java -path...
and what not by heart. Really fast too...

Thanks!

--
Regards
Konrad Viltersten
----------------------------------------
May all spammers die an agonizing death;
have no burial places; their souls be
chased by demons in Gehenna from one room
to another for all eternity and beyond.
Jul 26 '08 #8
K Viltersten wrote:
<snip>
>If you've got .NET 3.5 installed, you've got the C# 3.0 compiler
installed - but you can't make VS 2005 use it. So you could build C# 3
code from the command line, but not from VS 2005.

I'll consider it. It'll be like in the good old
days, when i could type:
javac Main.java -path...
and what not by heart. Really fast too...
Besides csc you can use msbuild or nant or ...

Arne
Jul 27 '08 #9
On Jul 26, 3:02*pm, "K Viltersten" <t...@viltersten.comwrote:
<snip>
If you've got .NET 3.5 installed, you've got the C# 3.0 compiler
installed - but you can't make VS 2005 use it. So you could build C# 3
code from the command line, but not from VS 2005.

I'll consider it. It'll be like in the good old
days, when i could type:
* javac Main.java -path...
and what not by heart. Really fast too...
Another reason not to stick to fancy syntactic sugar stuff like
"lambda expressions" and to do things the old fashioned (C#2.0) way.
I just reviewed lambda expressions this morning, as well as Action and
Func, and it seems an enormous waste of time, designed to impress
fellow programmers, like the ternary conditional operator ?:, rather
than to get the job done.

RL
Jul 27 '08 #10
Another reason not to stick to fancy syntactic
sugar stuff like "lambda expressions" and to do
things the old fashioned (C#2.0) way.
I just reviewed lambda expressions this morning,
as well as Action and Func, and it seems an
enormous waste of time, designed to impress
fellow programmers, like the ternary conditional
operator ?:, rather than to get the job done.
Oh, c'mon a bit. Sometimes it's nice to play with
your coworkers and typing some really complicated
code they haven't seen before, nodding the head
and asking, "what do you think, guys?". It's a
great way to learn who's got the cojones to admit
they don't know what's going on. :)

I warmly recommend the language of APL , if one
wishes to impress/scare/astonish colleagues...

--
Regards
Konrad Viltersten
----------------------------------------
May all spammers die an agonizing death;
have no burial places; their souls be
chased by demons in Gehenna from one room
to another for all eternity and beyond.
Jul 27 '08 #11
On Sun, 27 Jul 2008 08:39:36 -0700, K Viltersten <tm**@viltersten.com>
wrote:
[...]
>I just reviewed lambda expressions this morning,
as well as Action and Func, and it seems an
enormous waste of time, [...]

Oh, c'mon a bit.
Don't worry about Ray. He dismisses as useless pretty much everything in
C# that he doesn't fully understand. I don't think that will ever change.

Pete
Jul 27 '08 #12
raylopez99 <ra********@yahoo.comwrote:
Another reason not to stick to fancy syntactic sugar stuff like
"lambda expressions" and to do things the old fashioned (C#2.0) way.
I just reviewed lambda expressions this morning, as well as Action and
Func, and it seems an enormous waste of time, designed to impress
fellow programmers, like the ternary conditional operator ?:, rather
than to get the job done.
That suggests you haven't really understood how useful they can be - in
particular, LINQ relies on them.

Lambda expressions are very, very powerful. I just wish Java had them
:(

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Jul 27 '08 #13
On Jul 27, 12:37*pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
>
Don't worry about Ray. *He dismisses as useless pretty much everything in *
C# that he doesn't fully understand. *I don't think that will ever change.

That's not true. I dismissed as useless delegates until such time
that I started using them.

RL
Jul 28 '08 #14
On Jul 27, 1:31*pm, Jon Skeet [C# MVP] <sk...@pobox.comwrote:
raylopez99 <raylope...@yahoo.comwrote:
Another reason not to stick to fancy syntactic sugar stuff like
"lambda expressions" and to do things the old fashioned (C#2.0) way.
I just reviewed lambda expressions this morning, as well as Action and
Func, and it seems an enormous waste of time, designed to impress
fellow programmers, like the ternary conditional operator ?:, rather
than to get the job done.

That suggests you haven't really understood how useful they can be - in
particular, LINQ relies on them.

Lambda expressions are very, very powerful. I just wish Java had them
:(
LINQ is just a poor man's SQL. Be a man and learn the real thing.
That said, when I start learning LINQ I might change my mind...

RL
Jul 28 '08 #15
"raylopez99" <ra********@yahoo.comwrote in message
news:43**********************************@d45g2000 hsc.googlegroups.com...
LINQ is just a poor man's SQL. Be a man and learn the real thing.
That said, when I start learning LINQ I might change my mind...
How about learning it *before* dismissing it as being poor man's SQL? LINQ
is by far the best approach I've seen to integrate relational query syntax
into a "normal" language. Integration has many advantages that are otherwise
very hard to realize, e.g. compile-time type-safety.

Regards,

--
Andreas Huber

When replying by private email, please remove the words spam and trap
from the address shown in the header.

Jul 29 '08 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

53
by: Oliver Fromme | last post by:
Hi, I'm trying to write a Python function that parses an expression and builds a function tree from it (recursively). During parsing, lambda functions for the the terms and sub-expressions...
63
by: Stephen Thorne | last post by:
Hi guys, I'm a little worried about the expected disappearance of lambda in python3000. I've had my brain badly broken by functional programming in the past, and I would hate to see things...
6
by: Xavier Décoret | last post by:
Hi, I cannot find the way to do generic lambda functions using the lambda syntax in python. I am probably missing a point. For example, the code # f = lambda : print "hello" # f()
181
by: Tom Anderson | last post by:
Comrades, During our current discussion of the fate of functional constructs in python, someone brought up Guido's bull on the matter: http://www.artima.com/weblogs/viewpost.jsp?thread=98196 ...
5
by: Octal | last post by:
How does the lambda library actually works. How does it know how to evaluate _1, how does it recognize _1 as a placeholder, how does it then calculate _1+_2, or _1+2 etc. The source files seem a...
15
by: Matt | last post by:
Hi There, Can anyone explain me the real advantages of (other than syntax) lambda expressions over anonymous delegates? advantage for one over the other. delegate int F(int a); F fLambda = a...
2
by: =?Utf-8?B?UnV0aCBNYXJr?= | last post by:
Hey, Am trying to write a lambda expression for a delegate, am getting an error as ------------------------------ only assignment, call, increment, decrement, and new expression can be used as...
21
by: globalrev | last post by:
i have a rough understanding of lambda but so far only have found use for it once(in tkinter when passing lambda as an argument i could circumvent some tricky stuff). what is the point of the...
11
by: puzzlecracker | last post by:
I am not understanding what's happening in the code below (from accelerated c#) -- I know what the outcome but not how .net does it: using System; using System.Linq; public class LambdaTest...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.