Is there a reason to prefer one of these approaches over the other?
Maybe one is more efficient and should be preferred if doing a large
number of appends.
Approach #1
s := ''.
s := s, 'foo'.
s := s, 'bar'
Approach #2
stream := WriteStream on: ''.
stream nextPutAll: 'foo'.
stream
On Friday 03 Oct 2008 6:34:24 pm Mark Volkmann wrote:
Is there a way to break out of a do:? For example, if I use do: to
iterate through the characters in a string and I find a character I
don't want to allow, can I break out and avoid examining the remaining
characters?
A string is a
Mark == Mark Volkmann [EMAIL PROTECTED] writes:
Mark stream := WriteStream on: ''.
Mark stream nextPutAll: 'foo'.
Mark stream nextPutAll: 'bar'.
Mark s := stream contents
s := String streamContents: [:stream |
stream
nextPutAll: 'foo';
nextPutAll: 'bar'.
].
Then you don't
Randal L. Schwartz merlyn at stonehenge.com writes:
snip...
There are more complicated ways to do it with exceptions if you need
to stay within the same method. Don't do that. :)
For the fun of it, see also
Nicolas == Nicolas Cellier [EMAIL PROTECTED] writes:
Nicolas For the fun of it, see also
Nicolas
http://article.gmane.org/gmane.comp.lang.smalltalk.gnu.general/3375/match=break
Oww. I remember that. It makes my head hurt.
You could even go further:
Object valuedEscaper: aBlock
Hello Mark,
Friday, October 3, 2008, 4:52:39 PM, you wrote:
MV Is there a reason to prefer one of these approaches over the other?
MV Maybe one is more efficient and should be preferred if doing a large
MV number of appends.
speed is the reason for the stream approach. The #, approach copies
Am 03.10.2008 um 09:27 schrieb Randal L. Schwartz:
Nicolas == Nicolas Cellier [EMAIL PROTECTED] writes:
Nicolas For the fun of it, see also
Nicolas
http://article.gmane.org/gmane.comp.lang.smalltalk.gnu.general/3375/match=break
Oww. I remember that. It makes my head hurt.
You could
Bert == Bert Freudenberg [EMAIL PROTECTED] writes:
Bert That would be a perfect opportunity to employ
#valueWithPossibleArgument:.
And with this, the newbies heads have exploded. :)
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
[EMAIL PROTECTED]
Frank said...
I couldn't get Squeakmap to load IRCe, no errors just no action, but
when I downloaded the mcz file (Network-IRC-fc.10.7.6.mcz) and used
filelist to load it it came up fine. I was able to get onto the IRC
channel with no problem.
What is the 'package browser' you used to try and
Am 03.10.2008 um 11:02 schrieb Randal L. Schwartz:
Bert == Bert Freudenberg [EMAIL PROTECTED] writes:
Bert That would be a perfect opportunity to employ
#valueWithPossibleArgument:.
And with this, the newbies heads have exploded. :)
Hehe :) If they followed the thread closely they
Just check it by yourself. ;)
|result|
100 timesRepeat:
[ result := String new.
4000 timesRepeat: [ result := result, 'abcdefg' ]].
^result
|writer|
100 timesRepeat:
[ writer := WriteStream on: String new.
4000 timesRepeat: [ writer nextPutAll:'abcdefg' ]].
^writer contents
Cheers,
--
That reminds me. I know I ran across a method that runs a block and
then tells you how long it took. Anyone remember what that's called?
On Oct 3, 2008, at 3:09 PM, Mariano Abel Coca wrote:
Just check it by yourself. ;)
|result|
100 timesRepeat:
[ result := String new.
4000 timesRepeat: [
I think you must be thinking in #timeToRun.
About that... In VisualAge there are the EsbTracer and EsbSampler, which
allows you to meassure the time that involves every message sent. It's
useful to tune some code... But don't know in Squeak. Any ideas?
Cheers,
--
Mariano.
On Fri, Oct 3, 2008
On Oct 3, 2008, at 3:59 PM, Mariano Abel Coca wrote:
I think you must be thinking in #timeToRun.
No, but you saying that reminded me of where I saw it. It's in the
Time class.
ms := Time millisecondsToRun: [ do some stuff here ]
Using this on the code below, the comma approach took 8478
Why is it that when I do a print it on all the code below, it
outputs 'foobar'?
Shouldn't the writing of 'bar' fail because I've closed the stream?
ws := WriteStream on: ''.
ws nextPutAll: 'foo'.
ws close.
ws nextPutAll: 'bar'.
ws contents
---
Mark Volkmann
Am 03.10.2008 um 14:13 schrieb Mark Volkmann:
On Oct 3, 2008, at 3:59 PM, Mariano Abel Coca wrote:
I think you must be thinking in #timeToRun.
No, but you saying that reminded me of where I saw it. It's in the
Time class.
ms := Time millisecondsToRun: [ do some stuff here ]
which is
Actually, the definition of timeToRun in BlockContext is:
BlockContexttimeToRun
Answer the number of milliseconds taken to execute this block.
^ Time millisecondsToRun: self
So, your example it's the same than:
[ do some stuff here ] timeToRun
Remember: let the objects do the work
Thanks to all! Another thing to add to my growing set of notes.
On Oct 3, 2008, at 4:41 PM, Mariano Abel Coca wrote:
Actually, the definition of timeToRun in BlockContext is:
BlockContexttimeToRun
Answer the number of milliseconds taken to execute this block.
^ Time
Mark Volkmann a écrit :
Why is it that when I do a print it on all the code below, it outputs
'foobar'?
Shouldn't the writing of 'bar' fail because I've closed the stream?
ws := WriteStream on: ''.
ws nextPutAll: 'foo'.
ws close.
ws nextPutAll: 'bar'.
ws contents
---
Mark Volkmann
Close
If my head didn't explode, does that mean I'm not quite as new as I still
feel?
I still have to keep smacking myself to identify the real objects and their
behavior instead of pushing things around, but I actually followed this!
Thanks...it was a good example that made blocks seem a little
I can't find a method to give me a substring of a String from a given
index to the end. The copyFrom:to: method requires telling it the end.
Does a method exist where you only specify the starting point? I know
I could write it myself, but I don't want to do that if it's already
there.
Mark == Mark Volkmann [EMAIL PROTECTED] writes:
Mark I can't find a method to give me a substring of a String from a given
Mark index to the end. The copyFrom:to: method requires telling it the end.
Mark Does a method exist where you only specify the starting point? I know I
Mark could write it
22 matches
Mail list logo