how to do nested loops of variable depth? (<CSOTD> included!)
goran.hultgren at bluefish.se
goran.hultgren at bluefish.se
Fri Dec 21 06:26:07 UTC 2001
Hi guys!
"C. Gable Watts" <CGableWatts at Mac.com> wrote:
> Whenever I hear about data being held and processed in arrays and arrays-of-arrays, it is often a sign that perhaps this is an opportunity for more abstract objects to be used to hold the data. It is likely you should consider making new classes that are a better abstraction for the information represented by the data in these arrays and arrays-of-arrays. But, assuming these collections of arrays are a good abstraction for your data, you could transpose them in the following way:
I think you misread/misunderstood the problem in exactly the way I did!
Which makes me feel better since I now am not alone. ;-)
If you check his code again it isn't doing a transpose, it is doing a...
what's it called... "Give me all combinations of..."-thingy.
regards, Göran
PS. <CSOTD>
"My Celeste forces me to include all this darn code... Don't blaim me if
it sucks!"
"This code returns the source without C++ style comments like '//' and
'/*..*/'.
It is alittle buggy and does not handle nested comments..."
| start stop result last nextChar aSource |
aSource _ '// This is a comment\1 + 2\/* And this is one too. */\=3'
withCRs.
result _ WriteStream on: String new.
start _ 0.
last _ 1.
[ start _ aSource findString: '/' startingAt: start + 1.
start ~= 0 ] whileTrue: [
stop _ nil.
nextChar _ aSource at: start + 1.
nextChar = $/
ifTrue:[ stop _ (aSource indexOf: Character cr startingAt: start + 1)
- 1]
ifFalse:[
nextChar = $*
ifTrue:[ stop _ (aSource findString: '*/' startingAt: start + 1) +
1 ]].
stop
ifNotNil: [
result nextPutAll: (aSource copyFrom: last to: start - 1).
last _ stop + 1.
start _ stop + 1]
ifNil: [start _ start + 1]].
result nextPutAll: (aSource copyFrom: last to: aSource size).
^result contents
</CSOTD> DS
More information about the Squeak-dev
mailing list
|