Why doesn't this work?
strength := Array new: 10. strength := #( #(0 0 0 0) #(0 0 0 0) #(0 0 0 0) #(0 0 0 0) #(0 0 0 0) #(0 0 0 0) #(2 1 0 0) #( 8 4 0 1) #(14 6 0 2) #(30 12 1 4)).
I read that the contents of an array are objects and the arrays inside of strength are objects but Smalltalk simply refuses to accept this assignment. I didn't want to say a := #(0 0 0 0). b := #(2 1 0 0). c := #(8 4 0 1) ... etc. and then strength := #( a a a a a a b c ... etc but it appears this may be necessary. I suppose a, b, c, etc are temporary variables and will disappear after use but it seems like a terrible waste.
"Charles" == Charles Gray tcykgreis@gmail.com writes:
Charles> strength := Array new: 10.
You don't need to do that, if you're doing this:
Charles> strength := #( #(0 0 0 0) #(0 0 0 0) #(0 0 0 0) #(0 0 0 0) #(0 0 0 0) #(0 0 0 0) Charles> #(2 1 0 0) #( 8 4 0 1) #(14 6 0 2) #(30 12 1 4)).
And that works for me. What version are you using?
At Thu, 4 Sep 2008 15:14:44 +0000 (UTC), Charles Gray wrote:
Why doesn't this work?
strength := Array new: 10. strength := #( #(0 0 0 0) #(0 0 0 0) #(0 0 0 0) #(0 0 0 0) #(0 0 0 0) #(0 0 0 0) #(2 1 0 0) #( 8 4 0 1) #(14 6 0 2) #(30 12 1 4)).
Why do you have two assignments here?
The literal syntax has a bit of context sensitive-ness. In a literal array, the # is not necessary to mean nested literal array. So,
strength := #((0 0 0 0) (0 0 0 0) (0 0 0 0) (0 0 0 0) (0 0 0 0) (0 0 0 0) (2 1 0 0) (8 4 0 1) (14 6 0 2) (30 12 1 4)).
Also works.
I read that the contents of an array are objects and the arrays inside of strength are objects but Smalltalk simply refuses to accept this assignment. I didn't want to say a := #(0 0 0 0). b := #(2 1 0 0). c := #(8 4 0 1) ... etc. and then strength := #( a a a a a a b c ... etc but it appears this may be necessary. I suppose a, b, c, etc are temporary variables and will disappear after use but it seems like a terrible waste.
It doesn't refuse the assignment, right? And you can't use a variable in a literal array to mean the contents of the variable.
Or, the above is actually a simplified code, and some other object is holding onto the reference to the "Array new: 10" array? If you assign a new array created from the literal array syntax into the same name variable, the guy who is holding onto the reference to "Array new: 10" wouldn't see the change.
-- Yoshiki
Just curious, but what do these numbers represent?
<snip>
strength := #( #(0 0 0 0) #(0 0 0 0) #(0 0 0 0) #(0 0 0 0) #(0 0 0 0) #(0
0 0 0)
#(2 1 0 0) #( 8 4 0 1) #(14 6 0 2) #(30 12 1 4)).
<snip> The literal syntax has a bit of context sensitive-ness. In a literal array, the # is not necessary to mean nested literal array. So,
strength := #((0 0 0 0) (0 0 0 0) (0 0 0 0) (0 0 0 0) (0 0 0 0) (0 0 0 0) (2 1 0 0) (8 4 0 1) (14 6 0 2) (30 12 1 4)).
Also works.
<snip>
It doesn't refuse the assignment, right? And you can't use a variable in a literal array to mean the contents of the variable.
Or, the above is actually a simplified code, and some other object is holding onto the reference to the "Array new: 10" array? If you assign a new array created from the literal array syntax into the same name variable, the guy who is holding onto the reference to "Array new: 10" wouldn't see the change.
-- Yoshiki
Just curious, but what do these numbers represent?
Gee, that was easy. Thanks. I never guessed that you had to leave the #'s
off inside the array. Those particular numbers don't mean anything. They were just an example of my problem. In my bridge dealer program, there are four sets of values assigned to each card. The first two numbers give the relative strength of a card when playing in a suit contract and when playing in a notrump contract. The numbers are based on the extensive double-dummy analysis performed by Thomas Andrew. The third number is is what some players of the Moscito bidding system call AKQ or slam points, and the fourth number is simply a binary representation that I use for determining loser count. I wasn't trying to be sneaky. The real numbers from 8 up to ace are: #((2 1 0 0) (4 3 0 1) (10 6 0 2) (23 14 0 4) (43 27 1 8) (74 51 2 16) (115 82 3 16)). The totals are #(271 184 6 31). In the case of the first two numbers, I add them up for each suit, multiply by ten and divide by the total giving me a number from 0 to 40 that is similar to the work point count commonly used to evaluate bridge hands using 4, 3, 2, 1 for ace through jack for strength evaluation. Now that I think about it I can simply multiply each of the original numbers by 10 to eliminate that step.
I know that's more than you what to know about the numbers but you asked. The traditional 4, 3, 2, 1 evaluation undervalues aces and kings. Different numbers are used for suit play and notrump play because there is no chance that a card will be trumped during play. A human would find it difficult to use this method of evaluation but it is no problem for a computer. By the way, I was just converting procedures I had written in Forth and Ruby to Smalltalk. Now if I could just learn not to think in sequential terms.
Charlie
Charlie
At Fri, 5 Sep 2008 02:59:08 -0700, Charles Gray wrote:
Gee, that was easy. Thanks. I never guessed that you had to leave the #'s off inside the array.
I still wonder what version of image you are using. In the image I'm using, I can evalute:
#((0 0 0 0) (0 0 0 0) (0 0 0 0) (0 0 0 0) (0 0 0 0) (0 0 0 0) (2 1 0 0) (8 4 0 1) (14 6 0 2) (30 12 1 4)) = #(#(0 0 0 0) #(0 0 0 0) #(0 0 0 0) #(0 0 0 0) #(0 0 0 0) #(0 0 0 0) #(2 1 0 0) #( 8 4 0 1) #(14 6 0 2) #(30 12 1 4))
and get true.
Those particular numbers don't mean anything. They were just an example of my problem. In my bridge dealer program, there are four sets of values assigned to each card. The first two numbers give the relative strength of a card when playing in a suit contract and when playing in a notrump contract. The numbers are based on the extensive double-dummy analysis performed by Thomas Andrew. The third number is is what some players of the Moscito bidding system call AKQ or slam points, and the fourth number is simply a binary representation that I use for determining loser count. I wasn't trying to be sneaky. The real numbers from 8 up to ace are: #((2 1 0 0) (4 3 0 1) (10 6 0 2) (23 14 0 4) (43 27 1 8) (74 51 2 16) (115 82 3 16)). The totals are #(271 184 6 31). In the case of the first two numbers, I add them up for each suit, multiply by ten and divide by the total giving me a number from 0 to 40 that is similar to the work point count commonly used to evaluate bridge hands using 4, 3, 2, 1 for ace through jack for strength evaluation. Now that I think about it I can simply multiply each of the original numbers by 10 to eliminate that step.
I know that's more than you what to know about the numbers but you asked. The traditional 4, 3, 2, 1 evaluation undervalues aces and kings. Different numbers are used for suit play and notrump play because there is no chance that a card will be trumped during play. A human would find it difficult to use this method of evaluation but it is no problem for a computer. By the way, I was just converting procedures I had written in Forth and Ruby to Smalltalk. Now if I could just learn not to think in sequential terms.
Thank you!
-- Yoshiki
beginners@lists.squeakfoundation.org