[plt-scheme] Implicit begins (and programming style)

From: Joe Marshall (jrm at ccs.neu.edu)
Date: Wed Nov 24 09:12:16 EST 2004

Thomas-Xavier MARTIN <txm+plt-scheme at m4x.org> writes:

>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> Disclaimer : I am aware that scheme code should be as functional as possible, 
> and that begins are only necessary/useful/legitimate when side-effects are 
> needed. 

I'm not sure I'd agree with that.  The advantages of functional
programming are not unique to Scheme, and there isn't reason to treat
Scheme programming differently from, say, C or Java with regard to
writing functional code.

> But some programs need side-effects... So :
>
> Which forms include an implicit begin ?
>
> So far, I have noted :
> - lambda, define (for procedures, not for variables)
> - let, letrec, let*
> - cond, when, unless (not if !)
>
> Any others ? Any definitive list somewhere ?

I haven't seen a list that says `these forms have an implicit begin',
but you can extract that information from R5RS.  Of course any macro
could have an implicit begin, so there cannot be an exhaustive list.

Forms that have a `body', for instance, binding forms like LAMBDA,
LET, LETREC, etc. usually have an implicit begin.  Forms that have
cond-like clauses will often have implicit begins.

> Style-wise, should one write code with explicit begins even where they are not 
> needed, for readability (apart from specific cases with heavy indentation, I 
> do not see using explicit begins as more readable ; am I wrong ?) or on the 
> contrary, avoid writing begins anyplace it is possible for conciseness ?

I generally avoid writing an explicit begin unless it is necessary.
Since all but the last forms within the begin are used for
side-effects, they tend to stand out anyway (because of the !).




Posted on the users mailing list.