newbie question

Ken collins bibsybabs at hotmail.com
Mon Jul 12 05:19:27 UTC 1999


Hi,

PermaNewbie question here. Please forgive length: hopefully enough detail 
provided.
Looking for some insight on a bit of code that isn't doing what I expect.
Here it is:

=======================================================
| array pf oc1 oc2 |

array := #(0 3 1).

pf := array primeForm.

oc1 := OrderedCollection new.

(0 to: 11) do: [:each | oc1 add: (pf t: each) ].

oc2 := oc1 asArray.


"   ^pf     "
"   ^oc2    "
"   (oc2 includes: array)
	ifTrue: [ ^ 'T']
	ifFalse: [ ^ 'I']. "
==========================================================

1 - primeForm is a method I've added to ArrayedCollection. It just returns a 
sorted version of the receiver (same size as original).

2 - in the 1st block, t: is another method I added to ArrayedCollection:
	t: level
	^ self collect: [: each | ((each + level)mod12)].
I added mod12 to Integer - for my purposes, it just makes sure that "each" 
is between 0
and 12.

3 - the last 3 lines are in quotes so I can test (do it) each result easier 
(I do all of this in a Workspace). For example, removing the 1st quotation 
mark and highlighting everything from  ^pf  up and choosing to inspect it 
informs me that oc2 isn't used (I don't
remove it when asked) and the the inspector reveals an array: (0 1 3) - 
which is correct, thats what primeForm did to array: .


Removing only the 3rd quotation mark, highlighting everything from ^oc2 up, 
and choosing to inspect it gives this as the array: ((0 1 3 ) (1 2 4 ) (2 3 
5 ) (3 4 6 ) (4 5 7 ) (5 6 8 ) (6 7 9 ) (7 8 10 ) (8 9 11 ) (9 10 0 ) (10 11 
1 ) (11 0 2 ) ) .

So far, so good: exactly what I want. However, after removing only the last 
2 quotation marks (leaving the other 4), highlighting everything, and 
choosing to inspect it doesn't work as
thoroughly as I expect. In this case, the inspector shows the String 'T', 
which IS what I want.
Assigning any permutation of any of the first 9 arrays in oc2 -
((0 1 3 ) (1 2 4 ) (2 3 5 ) (3 4 6 ) (4 5 7 ) (5 6 8 ) (6 7 9 ) (7 8 10 ) (8 
9 11 ) (9 10 0 ) (10 11 1 ) (11 0 2 ) ) -
does what I expect: 'T' is returned. So, all of these assignments return 
'T':

array := #(0 1 3)
array := #(2 1 4)
array := #(5 3 2)
array := #(3 6 4)
array := #(4 5 7)
array := #(5 6 8)
array := #(9 7 6)
array := #(8 7 10)
array := #(11 8 9)
etc...

But, the last 3 arrays in oc2 return 'I' instead of 'T':

array := #(9 10 0)
array := #(0 9 10)

array := #(10 11 1)
array := #(1 11 10)

array := #(11 0 2)
array := #(0 2 11)
etc...

I don't understand why this happens. Why do the 1st 9 arrays (in oc2) return 
'T' and the last 3 return 'F' ???

The following makes sense (in a Workspace):

#( #(0 1 3 ) #(1 2 4 ) #(2 3 5 ) #(3 4 6 ) #(4 5 7 ) #(5 6 8 ) #(6 7 9 ) #(7 
8 10 ) #(8 9 11 ) #(9 10 0 ) #(10 11 1 ) #(11 0 2 ) )includes: #(0 1 3) 
"print it = true"
		or
includes: #(1 3 0) "print it = false"
		or					      includes: #(0 3 1) "print it = "false"
		or
includes: #(11 0 2) "print it = true"
		or
includes: #(0 1 3) "print it = true"

Maybe i've just been looking at this too long - it seemed like such a simple 
method (well, Workspace prelude to the method).  EEEEEEEAAAAAAAKKKKKKK !!!

Thanx for any help.

Ken Collins


_______________________________________________________________
Get Free Email and Do More On The Web. Visit http://www.msn.com





More information about the Squeak-dev mailing list