guile-user
[Top][All Lists]
Advanced

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

Re: C++ declaration style programming?


From: Keith Wright
Subject: Re: C++ declaration style programming?
Date: Wed, 21 Jan 2004 16:46:56 -0500

> From: Han-Wen Nienhuys  <address@hidden>
> 
> However, it doesn't work so well when I mix commands with
> declarations, eg.
> 
> 
>   int var1 = something ();
>   var1 += 2; 
>   int var2 = something (var1);
>   var2 += var1;
>   int var3 = something (var1, var2);  
>     etc.
> 

I realize this is just an example of syntax, several people
have pointed out that computing a value of 'var1' only to
change it has some lameness to it, but if you need to do that...

(let* ((var1 (let ((var1-ini (something)))
               (+ 2 var1-ini)))
       (var2 (let ((var2-ini (something var1)))
               (+ var2-ini var1)))
       (var3 (something var1 var2)) )
  etc)

You can use the first guess value as many times as you
need to compute the final value, but then it goes out
of scope and doesn't clutter all that follows.

If the imperative commands are part of computing the following
variable then...

(let*  ((var1 (something))
        (var2 (begin (set! var1 (+ 2 var1))
                     (something var1) ))
        (var3 (begin (set! var2 (+ var2 var1))
                     (something var1 var2) )))
  etc)

If the imperative stuff is not related to either the preceding
or following declaration, then maybe it should be moved out of
the middle.

Just a thought, hope this helps,
  do what you will is the whole of the law.
-- 
     -- Keith Wright  <address@hidden>

Programmer in Chief, Free Computer Shop <http://www.free-comp-shop.com>
         ---  Food, Shelter, Source code.  ---




reply via email to

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