POV-Ray : Newsgroups : povray.off-topic : My first C++ program : Re: A test Server Time
1 Oct 2024 00:03:14 EDT (-0400)
  Re: A test  
From: Mueen Nawaz
Date: 23 Sep 2008 11:22:57
Message: <48d909d1$1@news.povray.org>
Warp wrote:
>> Welll..... There's still a bunch of syntax. Template instantiation, << 
>> and >> for I/O, etc.  I mean, compare Haskell add-up-a-list-of-numbers 
>> to C++'s. Something like
>>    fold (+) my_list
>> to something like
>>    for (j = std::list.begin(); j != std::list.end(); j = j.next())
>>      i += j.value;
>> or some such. :-)
> 
>   At least the latter states more explicitly what you are doing.
> (And by the way, you advance an iterator with the ++ operator.)

	Yes, but imagine a conversation between two people. One of them says to 
the other:

1. Take a list of numbers.
2. Take the first element.
3. Add it to the variable i.
4. If you're not at the end of the list, take the next number and repeat 
step 3.

	As opposed to what Darren said:

"Take all the numbers, put a plus sign between them, and give me the 
result".

	I think the name functional programming is very apt. The latter is 
placing more emphasis on the "function" that we want (combining all the 
numbers to get a result).

	In Python, we have reduce, which is a simpler form of foldl (and 
perhaps a better name). Guido hates map, filter and reduce, but I love 
them. Sometimes I use a list comprehension or even an explicit for loop. 
But if in my mind it's "obvious" that what I want to do is a map or a 
reduce, then I write it that way.

	The reality is we don't *always* think procedurally. I'm sure even you 
in your head do occasionally think functionally. It's just that you're 
so used to converting that into a procedure that you don't notice it.

-- 
He's got a magnet!!!  Everybody BACKUP!!!!!!!!


                     /\  /\               /\  /
                    /  \/  \ u e e n     /  \/  a w a z
                        >>>>>>mue### [at] nawazorg<<<<<<
                                    anl


Post a reply to this message

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