lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: reading material?


From: Douglas A Linhardt
Subject: Re: reading material?
Date: Tue, 23 Mar 2004 12:29:45 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.1) Gecko/20020823 Netscape/7.0 (CK-LucentTPES)

I really struggled with whether I should responding to this thread any more.
I'm not trying to stir up controversy, but I hate when I'm unclear, and I end up
being misinterpretted.

I will try to keep this short, and hopefully non-controversial.  And then that's
it--no more responses from me to this thread.  I mean it.  I think.

Doug

On 3/22/2004 2:30 PM, Nicolas Sceaux wrote:

> 
> hm... "both natural and elegant"...
> Are you realizing that writing classes for everything is not natural,
> nor eleguant? Other programming paradigms do exist, and are notably
> more natural and eleguant for that particular problem.
> Your examples are very bright indeed, but a full page of C++ code against
> 5 lines of scheme code, is not very demonstrative.
> 

I was not comparing C++ to any other language.  And maybe "natural" is not the
right word (although I reserve the right to consider it elegant).  I was *only*
responding to this original statement about C++:

> Also it
> lacks a lot of features that I consider necessary for comfortable
> programming, like garbage collection, reflection and built-in strings,
> lists, dictionaries, vectors, and first-class functions.

Obviously, *Scheme and many other languages handle this better than C++, and not
all C++ functions are first-class.*  I have no argument with this.  I was merely
showing that C++ does have support for first-class functions as a
(poorly-understood?) part of the language.  If Han-Wen meant that functions in
C++ by default are not first-class, I would agree, and I wasted too much of
everybody's time.  I (mis)interpretted what he wrote and assumed that he meant
it is not possible to create first-class functions.  Sorry for the confusion.

Also, we should make sure we're comparing apples to apples.  My "full page of
C++ code" was 2 entire programs demonstrating the usage of the functor object,
as opposed to the code snippet that Han-Wen provided.  A more literal C++
translation of that snippet is 7 lines compared to Han-Wen's 5.  Here is a
comparison:

=================

Han-Wen's example:

=================

(define (iterate func k)
  "Produce the function x -> FUNC(FUNC .. (x) .. ) "
  (if (> k 0)
      (lambda (x) (func ((iterate func (1- k)) x)))
      (lambda (x) x)))

(define to-6th-power (iterate sqr 3))


=================

C++ equivalent

=================

template <typename FUNCTOR, typename TYPE, unsigned int ITERS>
struct Iterate {
        TYPE operator() (TYPE operand) {
                FUNCTOR func;
                for (int i = 0; i < ITERS; ++i) operand = func(operand);
                return operand; } };


typedef Iterate<Square, int, 3> TripleSquared;
- or -
class TripleSquared : public Iterate<Square, int, 3> {};
        





reply via email to

[Prev in Thread] Current Thread [Next in Thread]