🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #6862

Re: Should loop bodies be blocks?

#6862
From: Jack Campin
Date: Thu, 01 Mar 1990 19:03
33 lines
1891 bytes
jhallen@wpi.wpi.edu (Joseph H Allen) wrote:

> Which is preferred...  loop bodies which are blocks (I.E., with their own
> scope) or loop bodies which are part of scope the loop is in?

I can only think of one example where it makes a difference, in the
following piece of PS-algol code:

let ps := 1 :: 100 of proc ( -> int ); nullproc
! declare an array of 100 int-valued procedures,
! initializing them with the null procedure

for i = 1 to 100 do ps (i) := proc ( -> int ); i
! now the 57th procedure in the array will return 57.

! PS-algol is expression-oriented, hence no
! "return" statement in the procedure body.

This works because PS-algol puts an implicit scope round the loop body;
the value of "i" packaged in the closure is whatever value it had on that
iteration.  Without that, all the procedures in the array would return 100.

I must admit I've never yet found a practical use for this feature.  I
guess you can do the same in Scheme (which I think is more or less PS-algol
with Lisp syntax and no persistence)?  If anyone's found a use for it, it'll
be an AI hacker...

-- 
--  Jack Campin   Computing Science Department, Glasgow University, 17 Lilybank
Gardens, Glasgow G12 8QQ, Scotland   041 339 8855 x6044 work  041 556 1878 home
JANET: jack@cs.glasgow.ac.uk    BANG!net: via mcvax and ukc   FAX: 041 330 4913
INTERNET: via nsfnet-relay.ac.uk   BITNET: via UKACRL   UUCP: jack@glasgow.uucp
Technical Details
Message-ID: <4697@vanuata.cs.glasgow.ac.uk>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!strath-cs!cs.glasgow.ac.uk!jack
References: <9047@wpi.wpi.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!strath-cs!cs.glasgow.ac.uk!jack
From: jack@cs.glasgow.ac.uk (Jack Campin)
Newsgroups: comp.lang.misc
Subject: Re: Should loop bodies be blocks?
Message-ID: <4697@vanuata.cs.glasgow.ac.uk>
Date: 1 Mar 90 19:03:05 GMT
References: <9047@wpi.wpi.edu>
Reply-To: jack@cs.glasgow.ac.uk (Jack Campin)
Organization: COMANDOS Project, Glesga Yoonie, Unthank
Lines: 33