From: jrwats
Subject: (let ()) vs. (progn)
Date: 
Message-ID: <7710373d-bbb3-4801-87bb-504500734e41@a35g2000prf.googlegroups.com>
I've seen different styles for setting up blocks of code and was
wondering if there was any advantage or functional different to using:
(let ()
   (code...))

vs.

(progn
   (code...))

thanks,
JW

From: Frode Vatvedt Fjeld
Subject: Re: (let ()) vs. (progn)
Date: 
Message-ID: <2hlk815jgx.fsf@vserver.cs.uit.no>
jrwats <······@gmail.com> writes:

> I've seen different styles for setting up blocks of code and was
> wondering if there was any advantage or functional different to using:
> (let ()
>    (code...))
> 
> vs.
> 
> (progn
>    (code...))

The let form accepts declarations at the beginning of its body.

-- 
Frode Vatvedt Fjeld
From: Harald Hanche-Olsen
Subject: Re: (let ()) vs. (progn)
Date: 
Message-ID: <pcobq8v7r14.fsf@shuttle.math.ntnu.no>
+ Frode Vatvedt Fjeld <······@cs.uit.no>:

> jrwats <······@gmail.com> writes:
>
>> I've seen different styles for setting up blocks of code and was
>> wondering if there was any advantage or functional different to using:
>> (let ()
>>    (code...))
>> 
>> vs.
>> 
>> (progn
>>    (code...))
>
> The let form accepts declarations at the beginning of its body.

Since the top-level behaviour of PROGN has been pointed out elsewhere,
maybe I should add that LOCALLY has the same top-level behaviour, plus
(obviously) it accepts declarations.

-- 
* Harald Hanche-Olsen     <URL:http://www.math.ntnu.no/~hanche/>
- It is undesirable to believe a proposition
  when there is no ground whatsoever for supposing it is true.
  -- Bertrand Russell
From: Pascal Costanza
Subject: Re: (let ()) vs. (progn)
Date: 
Message-ID: <5s7pmvF17q7diU2@mid.individual.net>
jrwats wrote:
> I've seen different styles for setting up blocks of code and was
> wondering if there was any advantage or functional different to using:
> (let ()
>    (code...))
> 
> vs.
> 
> (progn
>    (code...))

progn maintains top-levelness of enclosed forms. So:

(progn
   (defun foo ...)
   (defun bar ...))

...behaves as if foo and bar were defined at the top level, which means 
that the compiler can make assumptions about their existence, etc.

In:

(let ()
   (defun foo ...)
   (defun bar ...))

...the compiler cannot make such assumptions, because it has to treat 
the enclosed code as something that is executed only at runtime.


Pascal

-- 
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
From: Timofei Shatrov
Subject: Re: (let ()) vs. (progn)
Date: 
Message-ID: <475ed5e5.36682997@news.motzarella.org>
On Tue, 11 Dec 2007 07:31:21 -0800 (PST), jrwats <······@gmail.com> tried to
confuse everyone with this message:

>I've seen different styles for setting up blocks of code and was
>wondering if there was any advantage or functional different to using:
>(let ()
>   (code...))
>
>vs.
>
>(progn
>   (code...))
>

Yes, there is a difference, however you're not likely to encounter it. 
progn is treated specially when it is a top-level form, as described here:

http://www.lisp.org/HyperSpec/Body/sec_3-2-3-1.html

-- 
|Don't believe this - you're not worthless              ,gr---------.ru
|It's us against millions and we can't take them all... |  ue     il   |
|But we can take them on!                               |     @ma      |
|                       (A Wilhelm Scream - The Rip)    |______________|
From: Maciej Katafiasz
Subject: Re: (let ()) vs. (progn)
Date: 
Message-ID: <fjn23q$86e$1@news.net.uni-c.dk>
Den Tue, 11 Dec 2007 18:32:10 +0000 skrev Timofei Shatrov:

> Yes, there is a difference, however you're not likely to encounter it.
> progn is treated specially when it is a top-level form, as described
> here:
> 
> http://www.lisp.org/HyperSpec/Body/sec_3-2-3-1.html

It's not so unlikely whenever there are non-trivial macros involved. 
PROGN maintaining top-levelness is crucial for defining macros.

That said, using (progn ...) has the important property of saying what 
you mean, which is not insignificant for code readability.

Cheers,
Maciej
From: Steven M. Haflich
Subject: Re: (let ()) vs. (progn)
Date: 
Message-ID: <gj08j.78003$YL5.4399@newssvr29.news.prodigy.net>
Maciej Katafiasz wrote:

> That said, using (progn ...) has the important property of saying what 
> you mean, which is not insignificant for code readability.

Indeed, this is important.  The _only_ difference between progn and
locally is whether declarations are allowed.  If there are no
declarations at the head of the body, these special operators should
be treated equivalently by and conforming implementation.

However, as a human code reader, when I see locally I expect that there
might be an important declaration that I should read, otherwise the code
author would have used progn.  The distinction is important for
readability.

Of course, locally was added to the language by X3J13 relatively lately.
progn has been in Lisp since before most programmers were born.