Bruno Mayerle Leite wrote:
> Im trying to implement some features of functional programming in C++. I
> think lazy lists can be useful since we can create infinite lists in some
> functional languages too. Imagine a very big list being traversed by an
> iterator and for some reason when the iterator reaches a certain Node the
> loop is over. In this case it isnt necessary to have the entire big list in
> memory. It is only one point that came to my mind.

Sounds an awful lot like what I tried to do when I first learned C...I 
wanted to bring my BASIC baggage with me to use familiar functions like 
Left(), Mid(), and Right().  I finally got that _functionality_ when I 
moved to Safe C++ but the _implementation_ is different.

I'm sure what you want to do is possible, but it may result in 
unreadable/unmaintainable code.  Just because something is possible 
doesn't mean you should do it.  In fact, you _shouldn't_ do it unless 
you have a VERY specific reason to do so.  Don't write code unless you 
actually need it.

The example provided by the document you showed can be done via a very 
simple class that increments an internal number:

class IncNumber
{
public:
   IncNumber(int Num)
   {
     MxInternal = Num;
   }

   inline int GetNext()
   {
     int x = MxInternal;
     MxInternal++;

     return x;
   }
   // Or you could get fancy and do the whole ostream << operator thing.

private:
   int MxInternal;
};

IncNumber MyNum(1);
for (x = 0; x < 10; x++)  cout << MyNum.GetNext() << endl;

Now I realize that it was just an example, but what I'm trying to say is 
that there is no need to write 
unmaintainable/unreadable/non-understandable code if you can avoid it. 
There's almost always a better way to implement something.

-- 
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197

*NEW* VerifyMyPC 2.5
Change tracking and management tool.
Reduce tech. support times from 2 hours to 5 minutes.

http://www.CubicleSoft.com/VerifyMyPC/

Reply via email to