unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* C++ declaration style programming?
@ 2004-01-20 22:17 Han-Wen Nienhuys
  2004-01-21  3:58 ` Viktor Pavlenko
                   ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: Han-Wen Nienhuys @ 2004-01-20 22:17 UTC (permalink / raw)



Hi there,

I just realized that one of the things that I dislike about Scheme is
that my habit of naming intermediate results (which I inherited from
C++) leads to deep nesting.

Usually in C++, I do

  int var1 = something ();
  int var2 = something (var1);  
  int var3 = something (var1, var2);  
    etc.

in Scheme, this translates quite well to (let* ) :

(let*
  ((var1 (something))
   (var2 (something var1))
   (var3 (something var1 var2)))
  .. )

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 would like to have some macro, where I can write the Scheme analogon
like

 (begin-let*
  (def var1 (something))
  (set! var1 (+ var1 2))
  (def var2 (something var1))
  (set! var2 (+ var2 var1))
  (def var3 (something var1 var2))
  ...  )


This can presumably be done by writing a macro begin-let* that expands
the statement list in a suitably nested let*

However, I was wondering whether there exists a standard library
syntax mechanism that lets me write code in this fashion.

-- 

 Han-Wen Nienhuys   |   hanwen@xs4all.nl   |   http://www.xs4all.nl/~hanwen 



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 14+ messages in thread
* Re: C++ declaration style programming?
@ 2004-01-21 14:22 Viktor Pavlenko
  2004-01-21 14:26 ` Han-Wen Nienhuys
  0 siblings, 1 reply; 14+ messages in thread
From: Viktor Pavlenko @ 2004-01-21 14:22 UTC (permalink / raw)
  Cc: guile-user

> From: Han-Wen Nienhuys  <hanwen@xs4all.nl>
> Date: 2004/01/21 Wed AM 07:40:42 EST
> 
> I think it looks stupid to do
> 
>   (let* ((a (something))
> 	 (unused (display a))
> 	 (b (something-else a))
> 	 ..
> 	 )
> 

Then what about this:

(let ((a (something)))
  (display a)
  (let ((b (something-else a)))
    ..

or

(let* ((a (something))
       (b (something-else a)))
  (display a)
  ..

Viktor





_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 14+ messages in thread
* Re: C++ declaration style programming?
@ 2004-01-21 15:41 Viktor Pavlenko
  2004-01-21 16:06 ` Paul Jarc
  2004-01-22  2:24 ` Thien-Thi Nguyen
  0 siblings, 2 replies; 14+ messages in thread
From: Viktor Pavlenko @ 2004-01-21 15:41 UTC (permalink / raw)
  Cc: guile-user

> From: Han-Wen Nienhuys  <hanwen@xs4all.nl>
> Date: 2004/01/21 Wed AM 09:26:12 EST

> > 
> > (let* ((a (something))
> >        (b (something-else a)))
> >   (display a)
> >   ..
> 
> Your 2nd is not always possible due to side effects [...]

let* is a binding construct by definition and it is an error to
bind the same identifier twice (r5rs). Using side effects to re-bind
a variable within the binding expression of let* sounds like cheating :)

Viktor





_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2004-01-22  4:28 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-01-20 22:17 C++ declaration style programming? Han-Wen Nienhuys
2004-01-21  3:58 ` Viktor Pavlenko
2004-01-21 12:40   ` Han-Wen Nienhuys
2004-01-21  4:57 ` Issac Trotts
2004-01-21  5:00 ` Stephen Compall
2004-01-21 12:45   ` Han-Wen Nienhuys
2004-01-21  5:03 ` Lynn Winebarger
2004-01-21 21:46 ` Keith Wright
  -- strict thread matches above, loose matches on Subject: below --
2004-01-21 14:22 Viktor Pavlenko
2004-01-21 14:26 ` Han-Wen Nienhuys
2004-01-21 15:41 Viktor Pavlenko
2004-01-21 16:06 ` Paul Jarc
2004-01-22  2:24 ` Thien-Thi Nguyen
2004-01-22  4:28   ` Viktor Pavlenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).