POV-Ray : Newsgroups : povray.off-topic : C# 4.0 Default parameters Server Time
9 Oct 2024 20:21:04 EDT (-0400)
  C# 4.0 Default parameters (Message 41 to 50 of 56)  
<<< Previous 10 Messages Goto Latest 10 Messages Next 6 Messages >>>
From: Mike Raiford
Subject: Re: C# 4.0 Default parameters
Date: 4 Feb 2009 14:31:56
Message: <4989ed2c@news.povray.org>
Warp wrote:
> Mike Raiford <"m[raiford]!at"@gmail.com> wrote:
>> Transparently.
> 
>> e.g.
> 
>> delegate void myDel(int x);
> 
>> class SomeClass
>> {
>>    public int myValue;
> 
>>    public void DoInstanceStuff(int x)
>>    {
>>      myValue = x;
>>    }
> 
>>    public static void Main()
>>    {
>>      SomeClass c = new SomeClass();
> 
>>      myDel d = c.DoInstanceStuff
> 
>>      d(6); // this sets c.myValue to 6;
> 
>>    }
>> }
> 
>   So you can't use the same function delegate for calling a member
> function of two different objects?
> 

No, I don't think you can. The closest you could get would be something 
like a multicast delegate. But, then you really cannot get a return value.
-- 
~Mike


Post a reply to this message

From: nemesis
Subject: Re: C# 4.0 Default parameters
Date: 4 Feb 2009 14:42:51
Message: <4989efbb@news.povray.org>
Warp escreveu:
> nemesis <nam### [at] gmailcom> wrote:
>> But that's within a function composition environment.
> 
>   Ah, so we avoid being related to the dreaded Object-Oriented Programming
> (vade retro) by using different terminology for the same things. Then we
> can write long lists of reasons why *our* terms do not *really* mean the
> same things as the equivalent OOP terms.

Not that.  I have no problem calling ADTs objects or parametrized 
regions of code subroutines, functions, procedures, methods or whatever, 
as long as it's not within a OO framework.  I like functional 
programming fluidity and lack of bureaucracy.


Post a reply to this message

From: Mike Raiford
Subject: Re: C# 4.0 Default parameters
Date: 4 Feb 2009 14:55:41
Message: <4989f2bd$1@news.povray.org>
Orchid XP v8 wrote:

>> This is how the mechanisms for querying SQL from C# work - you can 
>> write something like
>>   db.table["customers"].select(x => x.Name > "Henry")
>> and the "select()" function takes the AST describing that condition, 
>> translates it to SQL, and sends it to the database.
> 
> Lisp would be proud.
> 
> Does this transformation happen at compile-time or runtime?
> 

Runtime, I believe. The select extension function for the IQueryable 
interface takes an expression as its parameter. That expression object 
is whats used to build the expression tree. LinqToSQL uses that to build 
the SQL query.

-- 
~Mike


Post a reply to this message

From: Warp
Subject: Re: C# 4.0 Default parameters
Date: 4 Feb 2009 15:12:03
Message: <4989f692@news.povray.org>
nemesis <nam### [at] gmailcom> wrote:
> Not that.  I have no problem calling ADTs objects or parametrized 
> regions of code subroutines, functions, procedures, methods or whatever, 
> as long as it's not within a OO framework.  I like functional 
> programming fluidity and lack of bureaucracy.

  Well, I usually prefer encapsulation and abstraction over fancy
one-liners.

-- 
                                                          - Warp


Post a reply to this message

From: nemesis
Subject: Re: C# 4.0 Default parameters
Date: 4 Feb 2009 15:55:20
Message: <498a00b8$1@news.povray.org>
Warp escreveu:
> nemesis <nam### [at] gmailcom> wrote:
>> Not that.  I have no problem calling ADTs objects or parametrized 
>> regions of code subroutines, functions, procedures, methods or whatever, 
>> as long as it's not within a OO framework.  I like functional 
>> programming fluidity and lack of bureaucracy.
> 
>   Well, I usually prefer encapsulation and abstraction over fancy
> one-liners.

encapsulation and abstraction are conserved, thanks. :)


Post a reply to this message

From: Warp
Subject: Re: C# 4.0 Default parameters
Date: 4 Feb 2009 17:06:12
Message: <498a1154@news.povray.org>
nemesis <nam### [at] gmailcom> wrote:
> Warp escreveu:
> > nemesis <nam### [at] gmailcom> wrote:
> >> Not that.  I have no problem calling ADTs objects or parametrized 
> >> regions of code subroutines, functions, procedures, methods or whatever, 
> >> as long as it's not within a OO framework.  I like functional 
> >> programming fluidity and lack of bureaucracy.
> > 
> >   Well, I usually prefer encapsulation and abstraction over fancy
> > one-liners.

> encapsulation and abstraction are conserved, thanks. :)

  So you take what's great about OOP, rename it, and then say you hate OOP
and that it sucks, and that your own version is so much better.

-- 
                                                          - Warp


Post a reply to this message

From: Darren New
Subject: Re: C# 4.0 Default parameters
Date: 4 Feb 2009 19:06:26
Message: <498a2d82$1@news.povray.org>
Orchid XP v8 wrote:
> Darren New wrote:
>> Technically, I would think you could have a curried function in a 
>> language with named parameters pretty easily.
> 
> Yeah, I don't see why not. It's only a shortcut for creating a closure...

I mean, if you have named parameters, it would seem pretty easy to have a 
syntax for currying on any parameter.

>> That's where they're used in C#.
> I didn't think C# had curried functions like my example.

Yeah. Brain-oh. It does have closures, tho. Isn't that a very similar thing?

> Does this transformation happen at compile-time or runtime?

As far as I understand it, the AST is generated at compile time, but you can 
compile it into actual machine code at runtime.

-- 
   Darren New, San Diego CA, USA (PST)
   "Ouch ouch ouch!"
   "What's wrong? Noodles too hot?"
   "No, I have Chopstick Tunnel Syndrome."


Post a reply to this message

From: Darren New
Subject: Re: C# 4.0 Default parameters
Date: 4 Feb 2009 19:09:25
Message: <498a2e35$1@news.povray.org>
Warp wrote:
>   What if you want to call the function (through the pointer) for different
> objects?

I can't think of a convenient way offhand to do this in C#. I think here 
you'd likely fall back to a fixed-named function and then subclass objects 
(or inherit from interfaces) to do that.

I never found the need to orthogonally specify a function and an object to 
call it on, altho I imagine it might come up sometimes.

-- 
   Darren New, San Diego CA, USA (PST)
   "Ouch ouch ouch!"
   "What's wrong? Noodles too hot?"
   "No, I have Chopstick Tunnel Syndrome."


Post a reply to this message

From: nemesis
Subject: Re: C# 4.0 Default parameters
Date: 4 Feb 2009 20:44:48
Message: <498a4490$1@news.povray.org>
Warp wrote:
>   So you take what's great about OOP, rename it, and then say you hate OOP
> and that it sucks, and that your own version is so much better.

The way code flows, yes, it's much better.


Post a reply to this message

From: Darren New
Subject: Re: C# 4.0 Default parameters
Date: 4 Feb 2009 20:57:53
Message: <498a47a1@news.povray.org>
Mike Raiford wrote:
> No, I don't think you can. The closest you could get would be something 
> like a multicast delegate. But, then you really cannot get a return value.

I think you'd have to do something like this. First, you need an interface 
that defines all the possible functions you can call this way. That would be 
the equivalent of making all the objects subclasses of the same class in C++.

interface Istuff {
   int xyz(int x);
   int pdq(int x);
}

// Then a class that inherits from Istuff
class Mine : Istuff {
   int xyz(int x) { return x + 1; }
   int pdq(int x) { return x - 1; }
}

// Declare the type of a delegate that takes the object and integer and runs 
something.
delegate int do_it(Istuff on_what, int with_what);

// Declare two delegates, initializing them. One calls xyz, one calls pdq.
do_it use_xyz = ((Istuff on_what, int with_what) => on_what.xyz(with_what));
do_it use_pdq = ((Istuff on_what, int with_what) => on_what.pdq(with_what));

// Pick which one you want
void go_run_a_function(
   inputted_bool ? use_xyz : use_pdq,
   Istuff some_object, int parameter);


So, you can do it, basically by changing
   blah(object, parameter)
into
   object.blah(parameter)
with a lambda. But it's messy. Probably about as messy as going the other 
way in C++.  There's probably some fancy thing with generics you could do too.


-- 
   Darren New, San Diego CA, USA (PST)
   "Ouch ouch ouch!"
   "What's wrong? Noodles too hot?"
   "No, I have Chopstick Tunnel Syndrome."


Post a reply to this message

<<< Previous 10 Messages Goto Latest 10 Messages Next 6 Messages >>>

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.