473,395 Members | 1,905 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,395 software developers and data experts.

Extention on a Lambda function?

Is extentions only allowed on 'pure' methods?

I was playing arround with lambda functions and while googling I tried a
small example (In a static class):
public static Func<double, double, doubleHypotenuse = (x,y) =>
Math.Sqrt(x*x + y*y);
Now it would be cool if I could easily make it an extention on double, like:
public static Func<double, double, double, doubleHypotenuse = (this t,
x,y) =Math.Sqrt(x*x + y*y);

Is this even possible or am I just lost on syntax?

Regards

- Michael S


Mar 1 '07 #1
3 1487

"Michael S" <no@no.nowrote in message
news:OR**************@TK2MSFTNGP02.phx.gbl...

Was this question to hard, non-understandable or simply stupid?

Help me Jon-Skeet-Kenobi, your are my only hope.. =)

- Michael S
Mar 1 '07 #2
Michael S <no@no.nowrote:
"Michael S" <no@no.nowrote in message
news:OR**************@TK2MSFTNGP02.phx.gbl...

Was this question to hard, non-understandable or simply stupid?

Help me Jon-Skeet-Kenobi, your are my only hope.. =)
LOL. Unfortunately I haven't looked at C# 3.0 enough recently to know
for sure whether or not you could do it, but I don't see why you
shouldn't be able to put an extension on System.Double. On the other
hand, your method didn't use the "this" part, so I'm not sure how
useful it would be...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 1 '07 #3
Hello Michael,
>Is this even possible or am I just lost on syntax?
I made some tests with the following implementation:

class Program {
static void Main(string[] args) {
Console.WriteLine("Hi".AddSomething(" there"));
Console.WriteLine(Helper.AddSomethingLambda("Hi", " there"));

Console.ReadLine();
}

public static class Helper {
public static string AddSomething(this string val, string addOn) {
return val + addOn;
}

public static Func<string,string,stringAddSomethingLambda =
(val,addOn) =val + addOn;
}
}

I don't find a way to use the "this" keyword in the "AddSomethingLambda"
declaration that the compiler likes. Seems to me this doesn't work... it's
probably rather logical - extension methods work, afaik, because the
compiler converts the call into the "standard" syntax of a call to
Helper.XXX at compile time. While my example doesn't show this, it would
theoretically be possible that my AddSomethingLambda didn't even contain
anything - it's a runtime assignment, not something that can be evaluated
at compile time.
Oliver Sturm
--
http://www.sturmnet.org/blog
Mar 4 '07 #4

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...
26
by: Steven Bethard | last post by:
I thought it might be useful to put the recent lambda threads into perspective a bit. I was wondering what lambda gets used for in "real" code, so I grepped my Python Lib directory. Here are some...
4
by: markscottwright | last post by:
Just for the hell of it, I've been going through the old Scheme-based textbook "Structure and Interpretation of Computer Programs" and seeing what I can and can't do with python. I'm trying to...
17
by: mehmetmutigozel | last post by:
I was thinking about something like the following; >>> a= Traceback (most recent call last): File "<stdin>", line 1, in ? NameError: name 't' is not defined >>> or
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: Max Rybinsky | last post by:
Hello! Please take a look at the example. >>> a = # Just a list of tuples >>> a Now i want to get a list of functions x*y/n, for each (x, y) in a:
23
by: Kaz Kylheku | last post by:
I've been reading the recent cross-posted flamewar, and read Guido's article where he posits that embedding multi-line lambdas in expressions is an unsolvable puzzle. So for the last 15 minutes...
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...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.