Loading ...
Sorry, an error occurred while loading the content.

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

Expand Messages
  • Omer Musaev
    ... 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
    Message 1 of 3 , Mar 3, 2002
    • 0 Attachment
      > -----Original Message-----
      > From: Oleg Goldshmidt [mailto:ogoldshmidt@...]
      > Sent: Sunday, March 03, 2002 3:16 PM
      > To: hackers-il@yahoogroups.com
      > Subject: Re: [hackers-il] What the buzz? ( was: Re: Re: Prerequisite
      > lear ning? (was: Re: Re: The purpose of paradigms...) )
      >
      >
      > Omer Musaev <omerm@...> 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 | ogoldshmidt@...
      > 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:
      > hackers-il-unsubscribe@egroups.com
      >
      >
      >
      > Your use of Yahoo! Groups is subject to
      > http://docs.yahoo.com/info/terms/
      >
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.