Message-ID: <025332Z26101995@anon.penet.fi>
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!travelers.mail.cornell.edu!news.kei.com!news.mathworks.com!zombie.ncsc.mil!simtel!chi-news.cic.net!uwm.edu!math.ohio-state.edu!howland.reston.ans.net!EU.net!news.eunet.fi!anon.penet.fi
Newsgroups: comp.lang.smalltalk
From: an397723@anon.penet.fi (The Unknown Ranger)
X-Anonymously-To: comp.lang.smalltalk
Organization: Anonymous forwarding service
Reply-To: an397723@anon.penet.fi
Date: Thu, 26 Oct 1995 02:45:30 UTC
Subject: Scoping
Lines: 63




To: jan.bytesmiths@acm.org

Jan,

You were kind enough to answer a couple of my questions. Here's another.
You posted some of what's below about proper scoping.

>Besides having more tightly scoped code, why do you care? Performance.
>Here's a "before-after" test, letting the compiler declare the temp in
>each case:
>
 >   | i |
>    Time millisecondsToRun: [100000 timesRepeat: [i:=0]].
>
>averaged 138 mS, but:
>
>    Time millisecondsToRun: [| i |
>        100000 timesRepeat: [i:=0]].
>
>averaged 68 mS. This is because the first example creates a "copying"
>block, because it needs to reference the outer scope, while the second
>example creates a "clean" block, which can run without a method context.
>(The compiler didn't put the temp inside the "i:=0" block because
>#timesRepeat: is handled by the compiler -- it isn't a real message send,
>so the inner "block" isn't really a block.)

I tried running these in ST/V 2.0 (I know it's old but it's all I can 
afford). This second example would not run:

   Time millisecondsToRun: [| i |
        100000 timesRepeat: [i:=0]].

In ST/V, block variables are declared  as ": i |".  Does VW 2 use "| i |" 
instead, or have I misunderstood?  I changed the example to this:

   Time millisecondsToRun: [ :i |
        100000 timesRepeat: [i:=0]].

and got the message "Block needs 1 argument instead of 0".

BTW, I find your posts very interesting, although sometimes too technical 
for me.  I'd like to hear you expound more on what you consider the ill and 
overuse of class variables. Thanks.










 ----------------------------------------------------------------------------  
 --------------------------------------
--****ATTENTION****--****ATTENTION****--****ATTENTION****--***ATTENTION***
Your e-mail reply to this message WILL be *automatically* ANONYMIZED.
Please, report inappropriate use to                abuse@anon.penet.fi
For information (incl. non-anon reply) write to    help@anon.penet.fi
If you have any problems, address them to          admin@anon.penet.fi
