Subject: RE: [hackers-il] What the buzz? ( was: Re: Re: Prerequisite lear ning? (was: Re: Re: The purpose of paradigms...) )

From: Omer Musaev <[email-masked]>
Date: Sun, 3 Mar 2002 16:09:59 +0200

> -----Original Message-----
> From: Oleg Goldshmidt [mailto:[email-masked]]
> Sent: Sunday, March 03, 2002 3:16 PM
> To: [email-masked]
> Subject: Re: [hackers-il] What the buzz? ( was: Re: Re: Prerequisite
> lear ning? (was: Re: Re: The purpose of paradigms...) )
> 
> 
> Omer Musaev <[email-masked]> writes:
> 
> > Yes, of course. You can not realy create functions from scratch 
> > in runtime, but you can compose new functors from pre-made blocks.
> > Which enables using functions as first-class objects.
> 
> I am lost. Are you talking about function objects, say, an instance of
> a class inheriting from templates like unary_function<arg,res> etc? I
> am not sure it is a technique for representing true first-class
> functions (at run time - you seem to agree). It seems to me more a
> means of parametrizing behaviour. However, if I understand your drive
> correctly, I think I see what you are trying to say. Something like
> 
> #include <iostream>
> #include <functional>
> 
> // N should grok operator+
> template<class N> struct addto : public unary_function<N, N>
> {
> 	addto(N l) : lhs(l) {}
> 	N operator()(N x) { return lhs+x; }
> 	N lhs; 
> };
> 
> int main(void)
> {
> 	cout << addto<double>(1.0)(5.0) << endl;
> 	cout << addto<int>(8)(7) << endl;
> 	return 0;
> }
> 
> being sorta similar to (scheme syntax)
> 
> (define (addto r) (lambda (x) (+ r x)))
> ((addto 1) 5)
> ((addto 8) 7)
> 
> Is that what you meant?

Yes, with a correction/addition.

If you will consider using functor adaptors, such as STL's  
binder1st, binder2nd, unary_negate and binary_compose,
you will be able to perform composition and binding of functors.

> 
> -- 
> Oleg Goldshmidt | [email-masked] 
> Only wimps use tape backup: real men just upload their important 
> stuff on ftp, and let the rest of the world mirror it. [L. Torvalds]
> 
> ------------------------ Yahoo! Groups Sponsor 
> ---------------------~-->
> Tiny Wireless Camera under $80!
> Order Now! FREE VCR Commander!
> Click Here - Only 1 Day Left!
> http://us.click.yahoo.com/nuyOHD/7.PDAA/yigFAA/saFolB/TM
> --------------------------------------------------------------
> -------~->
> 
> To unsubscribe from this group, send an email to:
> [email-masked]
> 
>  
> 
> Your use of Yahoo! Groups is subject to 
> http://docs.yahoo.com/info/terms/ 
> 
>