Here:
| arr | arr := Dictionary newFrom: {'0000' -> '0'. '0001' -> '1'. '0010' -> '2'. '0011' -> '3'. '0100' -> '4'. '0101' -> '5'. '0110' -> '6'. '0111' -> '7'. '1000' -> '8'. '1001' -> '9'. '1010' -> 'A'. '1011' -> 'B'. '1100' -> 'C'. '1101' -> 'D'. '1110' -> 'E'. '1111' -> 'F'}. ^ (arr at: (t1 asString copyFrom: 1 to: 4)), (arr at: (t1 asString copyFrom: 5 to:8)), (arr at: (t1 asString copyFrom: 9 to: 12)), (arr at: (t1 asString copyFrom: 13 to: 16)), (arr at: (t1 asString copyFrom: 17 to: 20)), (arr at: (t1 asString copyFrom: 21 to: 24)).
Took me a while, I kept getting errors when my Dictionary turned into a String somehow...
EDIT: Oh no, the dreaded 46th page! (it's probably like 120 for other people)
Last edited by nXIII (2010-07-08 20:06:41)
Offline
nXIII wrote:
Here:
Code:
| arr | arr := Dictionary newFrom: {'0000' -> '0'. '0001' -> '1'. '0010' -> '2'. '0011' -> '3'. '0100' -> '4'. '0101' -> '5'. '0110' -> '6'. '0111' -> '7'. '1000' -> '8'. '1001' -> '9'. '1010' -> 'A'. '1011' -> 'B'. '1100' -> 'C'. '1101' -> 'D'. '1110' -> 'E'. '1111' -> 'F'}. ^ (arr at: (t1 asString copyFrom: 1 to: 4)), (arr at: (t1 asString copyFrom: 5 to:8)), (arr at: (t1 asString copyFrom: 9 to: 12)), (arr at: (t1 asString copyFrom: 13 to: 16)), (arr at: (t1 asString copyFrom: 17 to: 20)), (arr at: (t1 asString copyFrom: 21 to: 24)).Took me a while, I kept getting errors when my Dictionary turned into a String somehow...
EDIT: Oh no, the dreaded 46th page! (it's probably like 120 for other people)
Thanks! Somehow I knew you would come up with it...
Offline
Is there a way to make panther case sensitive?
I also am having this problem:
input = 05 - what panther recognizes: 5
It removes zeros if they are before a number. I'm making a decoder/encoder and it requires zeros to be used before numbers, and for panther to be case sensitive. Is there any way to impliment these features?
Offline
Jakey22 wrote:
Is there a way to make panther case sensitive?
I also am having this problem:
input = 05 - what panther recognizes: 5
It removes zeros if they are before a number. I'm making a decoder/encoder and it requires zeros to be used before numbers, and for panther to be case sensitive. Is there any way to impliment these features?
For the case sensitive part, go into CYOB, make a block called 'shift pressed?' and make it a boolean. For the code use this:
Sensor shiftPressed ifTrue: [^ true].
^ false
and for the 0's before numbers, you can't do it. Squeak automatically takes away 0's before numbers.
Offline
ScratchReallyROCKS wrote:
Jakey22 wrote:
Is there a way to make panther case sensitive?
I also am having this problem:
input = 05 - what panther recognizes: 5
It removes zeros if they are before a number. I'm making a decoder/encoder and it requires zeros to be used before numbers, and for panther to be case sensitive. Is there any way to impliment these features?For the case sensitive part, go into CYOB, make a block called 'shift pressed?' and make it a boolean. For the code use this:
Sensor shiftPressed ifTrue: [^ true].
^ false
and for the 0's before numbers, you can't do it. Squeak automatically takes away 0's before numbers.
^ Sensor shiftKeyPressed.
Offline
nXIII wrote:
ScratchReallyROCKS wrote:
Jakey22 wrote:
Is there a way to make panther case sensitive?
I also am having this problem:
input = 05 - what panther recognizes: 5
It removes zeros if they are before a number. I'm making a decoder/encoder and it requires zeros to be used before numbers, and for panther to be case sensitive. Is there any way to impliment these features?For the case sensitive part, go into CYOB, make a block called 'shift pressed?' and make it a boolean. For the code use this:
Sensor shiftPressed ifTrue: [^ true].
^ false
and for the 0's before numbers, you can't do it. Squeak automatically takes away 0's before numbers.^ Sensor shiftKeyPressed.
actually it's shiftPressed, not shiftKeyPressed, but other than that, this is SO much better than mine because its SO much shorter.
Offline
ScratchReallyROCKS wrote:
nXIII wrote:
ScratchReallyROCKS wrote:
For the case sensitive part, go into CYOB, make a block called 'shift pressed?' and make it a boolean. For the code use this:
Sensor shiftPressed ifTrue: [^ true].
^ false
and for the 0's before numbers, you can't do it. Squeak automatically takes away 0's before numbers.^ Sensor shiftKeyPressed.
actually it's shiftPressed, not shiftKeyPressed, but other than that, this is SO much better than mine because its SO much shorter.
Ah. From memory, you see...
Last edited by nXIII (2010-07-08 22:17:22)
Offline
ScratchReallyROCKS wrote:
can someone tell me what's wrong with this script? (I made it in CYOB and it's supposed to convert 24 bit binary numbers to hexadecimal values.)
A binary number is not a string of characters. You can look on it as a string of bits, but that's not very helpful in this situation -- you really just want to think of it as a number, and do arithmetic on it, as opposed to string operations.
So. Take your binary number, call it num. Then
<num> MOD <16>
is the value of the four rightmost bits of the number. That value is itself a number, between 0 and 15. You can use it to index into the string "0123456789abcdef" to find the character that represents the rightmost four bits.
So, that's the rightmost character. What about the other characters? Well, compute the value
( (<num> - (<num> MOD <16>) ) / 16 )
The dividend is divisible by 16, so the quotient is an integer. You can do the same trick with this smaller number to find the next-to-rightmost character, etc.
This is a recursive procedure. I am refraining from writing it in BYOB so the Panther people don't yell at me. You can write it in Smalltalk, too.
Offline
ScratchReallyROCKS wrote:
johnnydean1 wrote:
I remade all of that and it works:
Code:
|length n1 n2 n3 n4 n5 n6 num hex x1 m1 c1 h1| n1_ 0000. n2_ 0000. n3_ 0000. n4_ 0000. n5_ 0000. n6_ 0000. length_ self stringLength: (t1). length > 23 ifTrue: [ n1_ self letters: (21) through: (24) of: (t1). n1_ n1 asString. ]. length > 19 ifTrue: [ n2_ self letters: (17) through: (20) of: (t1). n2_ n2 asString. ]. length > 15 ifTrue: [ n3_ self letters: (13) through: (16) of: (t1). n3_ n3 asString. ]. length > 11 ifTrue: [ n4_ self letters: (9) through: (12) of: (t1). n4_ n4 asString. ]. length > 7 ifTrue: [ n5_ self letters: (5) through: (8) of: (t1). n5_ n5 asString. ]. length > 3 ifTrue: [ n6_ self letters: (1) through: (4) of: (t1). n6_ n6 asString. ]. x1_ self letter: (4) of: (n1). x1_ x1 asNumber. x1_ x1 * 1. c1_ self letter: (3) of: (n1). c1_ c1 asNumber. c1_ c1 * 2. m1_ self letter: (2) of: (n1). m1_ m1 asNumber. m1_ m1 * 4. h1_ self letter: (1) of: (n1). h1_ h1 asNumber. h1_ h1 * 8. n1_ x1 + c1. n1_ n1 + m1. n1_ n1 + h1. x1_ self letter: (4) of: (n2). x1_ x1 asNumber. x1_ x1 * 1. c1_ self letter: (3) of: (n2). c1_ c1 asNumber. c1_ c1 * 2. m1_ self letter: (2) of: (n2). m1_ m1 asNumber. m1_ m1 * 4. h1_ self letter: (1) of: (n2). h1_ h1 asNumber. h1_ h1 * 8. n2_ x1 + c1. n2_ n2 + m1. n2_ n2 + h1. x1_ self letter: (4) of: (n3). x1_ x1 asNumber. x1_ x1 * 1. c1_ self letter: (3) of: (n3). c1_ c1 asNumber. c1_ c1 * 2. m1_ self letter: (2) of: (n3). m1_ m1 asNumber. m1_ m1 * 4. h1_ self letter: (1) of: (n3). h1_ h1 asNumber. h1_ h1 * 8. n3_ x1 + c1. n3_ n3 + m1. n3_ n3 + h1. x1_ self letter: (4) of: (n4). x1_ x1 asNumber. x1_ x1 * 1. c1_ self letter: (3) of: (n4). c1_ c1 asNumber. c1_ c1 * 2. m1_ self letter: (2) of: (n4). m1_ m1 asNumber. m1_ m1 * 4. h1_ self letter: (1) of: (n4). h1_ h1 asNumber. h1_ h1 * 8. n4_ x1 + c1. n4_ n4 + m1. n4_ n4 + h1. x1_ self letter: (4) of: (n5). x1_ x1 asNumber. x1_ x1 * 1. c1_ self letter: (3) of: (n5). c1_ c1 asNumber. c1_ c1 * 2. m1_ self letter: (2) of: (n5). m1_ m1 asNumber. m1_ m1 * 4. h1_ self letter: (1) of: (n5). h1_ h1 asNumber. h1_ h1 * 8. n5_ x1 + c1. n5_ n5 + m1. n5_ n5 + h1. x1_ self letter: (4) of: (n6). x1_ x1 asNumber. x1_ x1 * 1. c1_ self letter: (3) of: (n6). c1_ c1 asNumber. c1_ c1 * 2. m1_ self letter: (2) of: (n6). m1_ m1 asNumber. m1_ m1 * 4. h1_ self letter: (1) of: (n6). h1_ h1 asNumber. h1_ h1 * 8. n6_ x1 + c1. n6_ n6 + m1. n6_ n6 + h1. num_ ''. num_ self concatenate: (num) with: (n1). num_ self concatenate: (num) with: (n2). num_ self concatenate: (num) with: (n3). num_ self concatenate: (num) with: (n4). num_ self concatenate: (num) with: (n5). num_ self concatenate: (num) with: (n6). ^ numYou owe me big time this took me about 1 hour!
It may have taken you an hour, but it's still not what I want. I need a code that converts a a 24 bit binary number into a hexadecimal value. Use this to see how binary and hexadecimal numbers line up:
Binary | Hexadecimal
0000 | 0
0001 | 1
0010 | 2
0011 | 3
0100 | 4
0101 | 5
0110 | 6
0111 | 7
1000 | 8
1001 | 9
1010 | A
1011 | B
1100 | C
1101 | D
1110 | E
1111 | Fso that means that hexadecimal FFFFFF or white, would be 111111111111111111111111 in binary, and hexadecimal 0000FF or blue, would be 000000000000000011111111 in binary.
Well the code you put before is the same as that when it works.
Offline
johnnydean1 wrote:
ScratchReallyROCKS wrote:
johnnydean1 wrote:
I remade all of that and it works:
Code:
|length n1 n2 n3 n4 n5 n6 num hex x1 m1 c1 h1| n1_ 0000. n2_ 0000. n3_ 0000. n4_ 0000. n5_ 0000. n6_ 0000. length_ self stringLength: (t1). length > 23 ifTrue: [ n1_ self letters: (21) through: (24) of: (t1). n1_ n1 asString. ]. length > 19 ifTrue: [ n2_ self letters: (17) through: (20) of: (t1). n2_ n2 asString. ]. length > 15 ifTrue: [ n3_ self letters: (13) through: (16) of: (t1). n3_ n3 asString. ]. length > 11 ifTrue: [ n4_ self letters: (9) through: (12) of: (t1). n4_ n4 asString. ]. length > 7 ifTrue: [ n5_ self letters: (5) through: (8) of: (t1). n5_ n5 asString. ]. length > 3 ifTrue: [ n6_ self letters: (1) through: (4) of: (t1). n6_ n6 asString. ]. x1_ self letter: (4) of: (n1). x1_ x1 asNumber. x1_ x1 * 1. c1_ self letter: (3) of: (n1). c1_ c1 asNumber. c1_ c1 * 2. m1_ self letter: (2) of: (n1). m1_ m1 asNumber. m1_ m1 * 4. h1_ self letter: (1) of: (n1). h1_ h1 asNumber. h1_ h1 * 8. n1_ x1 + c1. n1_ n1 + m1. n1_ n1 + h1. x1_ self letter: (4) of: (n2). x1_ x1 asNumber. x1_ x1 * 1. c1_ self letter: (3) of: (n2). c1_ c1 asNumber. c1_ c1 * 2. m1_ self letter: (2) of: (n2). m1_ m1 asNumber. m1_ m1 * 4. h1_ self letter: (1) of: (n2). h1_ h1 asNumber. h1_ h1 * 8. n2_ x1 + c1. n2_ n2 + m1. n2_ n2 + h1. x1_ self letter: (4) of: (n3). x1_ x1 asNumber. x1_ x1 * 1. c1_ self letter: (3) of: (n3). c1_ c1 asNumber. c1_ c1 * 2. m1_ self letter: (2) of: (n3). m1_ m1 asNumber. m1_ m1 * 4. h1_ self letter: (1) of: (n3). h1_ h1 asNumber. h1_ h1 * 8. n3_ x1 + c1. n3_ n3 + m1. n3_ n3 + h1. x1_ self letter: (4) of: (n4). x1_ x1 asNumber. x1_ x1 * 1. c1_ self letter: (3) of: (n4). c1_ c1 asNumber. c1_ c1 * 2. m1_ self letter: (2) of: (n4). m1_ m1 asNumber. m1_ m1 * 4. h1_ self letter: (1) of: (n4). h1_ h1 asNumber. h1_ h1 * 8. n4_ x1 + c1. n4_ n4 + m1. n4_ n4 + h1. x1_ self letter: (4) of: (n5). x1_ x1 asNumber. x1_ x1 * 1. c1_ self letter: (3) of: (n5). c1_ c1 asNumber. c1_ c1 * 2. m1_ self letter: (2) of: (n5). m1_ m1 asNumber. m1_ m1 * 4. h1_ self letter: (1) of: (n5). h1_ h1 asNumber. h1_ h1 * 8. n5_ x1 + c1. n5_ n5 + m1. n5_ n5 + h1. x1_ self letter: (4) of: (n6). x1_ x1 asNumber. x1_ x1 * 1. c1_ self letter: (3) of: (n6). c1_ c1 asNumber. c1_ c1 * 2. m1_ self letter: (2) of: (n6). m1_ m1 asNumber. m1_ m1 * 4. h1_ self letter: (1) of: (n6). h1_ h1 asNumber. h1_ h1 * 8. n6_ x1 + c1. n6_ n6 + m1. n6_ n6 + h1. num_ ''. num_ self concatenate: (num) with: (n1). num_ self concatenate: (num) with: (n2). num_ self concatenate: (num) with: (n3). num_ self concatenate: (num) with: (n4). num_ self concatenate: (num) with: (n5). num_ self concatenate: (num) with: (n6). ^ numYou owe me big time this took me about 1 hour!
It may have taken you an hour, but it's still not what I want. I need a code that converts a a 24 bit binary number into a hexadecimal value. Use this to see how binary and hexadecimal numbers line up:
Binary | Hexadecimal
0000 | 0
0001 | 1
0010 | 2
0011 | 3
0100 | 4
0101 | 5
0110 | 6
0111 | 7
1000 | 8
1001 | 9
1010 | A
1011 | B
1100 | C
1101 | D
1110 | E
1111 | Fso that means that hexadecimal FFFFFF or white, would be 111111111111111111111111 in binary, and hexadecimal 0000FF or blue, would be 000000000000000011111111 in binary.
Well the code you put before is the same as that when it works.
Yeah but the code I put before wasn't the whole thing.
Offline
So post the whole thing!
Offline
johnnydean1 wrote:
So post the whole thing!
I don't need to anymore! nXIII gave me a code that works.
Offline
Oh man I just did this:
|length n1 n2 n3 n4 n5 n6 num x1 c1 input| input_ t1. input_ input asString. n1_ 0000. n2_ 0000. n3_ 0000. n4_ 0000. n5_ 0000. n6_ 0000. length_ self stringLength: (input). length > 23 ifTrue: [ n1_ self letters: (21) through: (24) of: (input). n1_ n1 asNumber. ]. length > 19 ifTrue: [ n2_ self letters: (17) through: (20) of: (input). n2_ n2 asNumber. ]. length > 15 ifTrue: [ n3_ self letters: (13) through: (16) of: (input). n3_ n3 asNumber. ]. length > 11 ifTrue: [ n4_ self letters: (9) through: (12) of: (input). n4_ n4 asNumber. ]. length > 7 ifTrue: [ n5_ self letters: (5) through: (8) of: (input). n5_ n5 asNumber. ]. length > 3 ifTrue: [ n6_ self letters: (1) through: (4) of: (input). n6_ n6 asNumber. ]. c1_ n1. c1 = 0000 ifTrue: [ x1_ 0. ]. c1 = 0001 ifTrue: [ x1_ 1. ]. c1 = 0010 ifTrue: [ x1_ 2. ]. c1 = 0011 ifTrue: [ x1_ 3. ]. c1 = 0100 ifTrue: [ x1_ 4. ]. c1 = 0101 ifTrue: [ x1_ 5. ]. c1 = 0110 ifTrue: [ x1_ 6. ]. c1 = 0111 ifTrue: [ x1_ 7. ]. c1 = 1000 ifTrue: [ x1_ 8. ]. c1 = 1001 ifTrue: [ x1_ 9. ]. c1 = 1010 ifTrue: [ x1_ 'A'. ]. c1 = 1011 ifTrue: [ x1_ 'B'. ]. c1 = 1100 ifTrue: [ x1_ 'C'. ]. c1 = 1101 ifTrue: [ x1_ 'D'. ]. c1 = 1110 ifTrue: [ x1_ 'E'. ]. c1 = 1111 ifTrue: [ x1_ 'F'. ]. n1_ x1. c1_ n2. c1 = 0000 ifTrue: [ x1_ 0. ]. c1 = 0001 ifTrue: [ x1_ 1. ]. c1 = 0010 ifTrue: [ x1_ 2. ]. c1 = 0011 ifTrue: [ x1_ 3. ]. c1 = 0100 ifTrue: [ x1_ 4. ]. c1 = 0101 ifTrue: [ x1_ 5. ]. c1 = 0110 ifTrue: [ x1_ 6. ]. c1 = 0111 ifTrue: [ x1_ 7. ]. c1 = 1000 ifTrue: [ x1_ 8. ]. c1 = 1001 ifTrue: [ x1_ 9. ]. c1 = 1010 ifTrue: [ x1_ 'A'. ]. c1 = 1011 ifTrue: [ x1_ 'B'. ]. c1 = 1100 ifTrue: [ x1_ 'C'. ]. c1 = 1101 ifTrue: [ x1_ 'D'. ]. c1 = 1110 ifTrue: [ x1_ 'E'. ]. c1 = 1111 ifTrue: [ x1_ 'F'. ]. n2_ x1. c1_ n3. c1 = 0000 ifTrue: [ x1_ 0. ]. c1 = 0001 ifTrue: [ x1_ 1. ]. c1 = 0010 ifTrue: [ x1_ 2. ]. c1 = 0011 ifTrue: [ x1_ 3. ]. c1 = 0100 ifTrue: [ x1_ 4. ]. c1 = 0101 ifTrue: [ x1_ 5. ]. c1 = 0110 ifTrue: [ x1_ 6. ]. c1 = 0111 ifTrue: [ x1_ 7. ]. c1 = 1000 ifTrue: [ x1_ 8. ]. c1 = 1001 ifTrue: [ x1_ 9. ]. c1 = 1010 ifTrue: [ x1_ 'A'. ]. c1 = 1011 ifTrue: [ x1_ 'B'. ]. c1 = 1100 ifTrue: [ x1_ 'C'. ]. c1 = 1101 ifTrue: [ x1_ 'D'. ]. c1 = 1110 ifTrue: [ x1_ 'E'. ]. c1 = 1111 ifTrue: [ x1_ 'F'. ]. n3_ x1. c1_ n4. c1 = 0000 ifTrue: [ x1_ 0. ]. c1 = 0001 ifTrue: [ x1_ 1. ]. c1 = 0010 ifTrue: [ x1_ 2. ]. c1 = 0011 ifTrue: [ x1_ 3. ]. c1 = 0100 ifTrue: [ x1_ 4. ]. c1 = 0101 ifTrue: [ x1_ 5. ]. c1 = 0110 ifTrue: [ x1_ 6. ]. c1 = 0111 ifTrue: [ x1_ 7. ]. c1 = 1000 ifTrue: [ x1_ 8. ]. c1 = 1001 ifTrue: [ x1_ 9. ]. c1 = 1010 ifTrue: [ x1_ 'A'. ]. c1 = 1011 ifTrue: [ x1_ 'B'. ]. c1 = 1100 ifTrue: [ x1_ 'C'. ]. c1 = 1101 ifTrue: [ x1_ 'D'. ]. c1 = 1110 ifTrue: [ x1_ 'E'. ]. c1 = 1111 ifTrue: [ x1_ 'F'. ]. n4_ x1. c1_ n5. c1 = 0000 ifTrue: [ x1_ 0. ]. c1 = 0001 ifTrue: [ x1_ 1. ]. c1 = 0010 ifTrue: [ x1_ 2. ]. c1 = 0011 ifTrue: [ x1_ 3. ]. c1 = 0100 ifTrue: [ x1_ 4. ]. c1 = 0101 ifTrue: [ x1_ 5. ]. c1 = 0110 ifTrue: [ x1_ 6. ]. c1 = 0111 ifTrue: [ x1_ 7. ]. c1 = 1000 ifTrue: [ x1_ 8. ]. c1 = 1001 ifTrue: [ x1_ 9. ]. c1 = 1010 ifTrue: [ x1_ 'A'. ]. c1 = 1011 ifTrue: [ x1_ 'B'. ]. c1 = 1100 ifTrue: [ x1_ 'C'. ]. c1 = 1101 ifTrue: [ x1_ 'D'. ]. c1 = 1110 ifTrue: [ x1_ 'E'. ]. c1 = 1111 ifTrue: [ x1_ 'F'. ]. n5_ x1. c1_ n6. c1 = 0000 ifTrue: [ x1_ 0. ]. c1 = 0001 ifTrue: [ x1_ 1. ]. c1 = 0010 ifTrue: [ x1_ 2. ]. c1 = 0011 ifTrue: [ x1_ 3. ]. c1 = 0100 ifTrue: [ x1_ 4. ]. c1 = 0101 ifTrue: [ x1_ 5. ]. c1 = 0110 ifTrue: [ x1_ 6. ]. c1 = 0111 ifTrue: [ x1_ 7. ]. c1 = 1000 ifTrue: [ x1_ 8. ]. c1 = 1001 ifTrue: [ x1_ 9. ]. c1 = 1010 ifTrue: [ x1_ 'A'. ]. c1 = 1011 ifTrue: [ x1_ 'B'. ]. c1 = 1100 ifTrue: [ x1_ 'C'. ]. c1 = 1101 ifTrue: [ x1_ 'D'. ]. c1 = 1110 ifTrue: [ x1_ 'E'. ]. c1 = 1111 ifTrue: [ x1_ 'F'. ]. n6_ x1. num_ '#'. num_ self concatenate: (num) with: (n1). num_ self concatenate: (num) with: (n2). num_ self concatenate: (num) with: (n3). num_ self concatenate: (num) with: (n4). num_ self concatenate: (num) with: (n5). num_ self concatenate: (num) with: (n6). ^ num
Offline
johnnydean1 wrote:
Oh man I just did this:
Code:
|length n1 n2 n3 n4 n5 n6 num x1 c1 input| input_ t1. input_ input asString. n1_ 0000. n2_ 0000. n3_ 0000. n4_ 0000. n5_ 0000. n6_ 0000. length_ self stringLength: (input). length > 23 ifTrue: [ n1_ self letters: (21) through: (24) of: (input). n1_ n1 asNumber. ]. length > 19 ifTrue: [ n2_ self letters: (17) through: (20) of: (input). n2_ n2 asNumber. ]. length > 15 ifTrue: [ n3_ self letters: (13) through: (16) of: (input). n3_ n3 asNumber. ]. length > 11 ifTrue: [ n4_ self letters: (9) through: (12) of: (input). n4_ n4 asNumber. ]. length > 7 ifTrue: [ n5_ self letters: (5) through: (8) of: (input). n5_ n5 asNumber. ]. length > 3 ifTrue: [ n6_ self letters: (1) through: (4) of: (input). n6_ n6 asNumber. ]. c1_ n1. c1 = 0000 ifTrue: [ x1_ 0. ]. c1 = 0001 ifTrue: [ x1_ 1. ]. c1 = 0010 ifTrue: [ x1_ 2. ]. c1 = 0011 ifTrue: [ x1_ 3. ]. c1 = 0100 ifTrue: [ x1_ 4. ]. c1 = 0101 ifTrue: [ x1_ 5. ]. c1 = 0110 ifTrue: [ x1_ 6. ]. c1 = 0111 ifTrue: [ x1_ 7. ]. c1 = 1000 ifTrue: [ x1_ 8. ]. c1 = 1001 ifTrue: [ x1_ 9. ]. c1 = 1010 ifTrue: [ x1_ 'A'. ]. c1 = 1011 ifTrue: [ x1_ 'B'. ]. c1 = 1100 ifTrue: [ x1_ 'C'. ]. c1 = 1101 ifTrue: [ x1_ 'D'. ]. c1 = 1110 ifTrue: [ x1_ 'E'. ]. c1 = 1111 ifTrue: [ x1_ 'F'. ]. n1_ x1. c1_ n2. c1 = 0000 ifTrue: [ x1_ 0. ]. c1 = 0001 ifTrue: [ x1_ 1. ]. c1 = 0010 ifTrue: [ x1_ 2. ]. c1 = 0011 ifTrue: [ x1_ 3. ]. c1 = 0100 ifTrue: [ x1_ 4. ]. c1 = 0101 ifTrue: [ x1_ 5. ]. c1 = 0110 ifTrue: [ x1_ 6. ]. c1 = 0111 ifTrue: [ x1_ 7. ]. c1 = 1000 ifTrue: [ x1_ 8. ]. c1 = 1001 ifTrue: [ x1_ 9. ]. c1 = 1010 ifTrue: [ x1_ 'A'. ]. c1 = 1011 ifTrue: [ x1_ 'B'. ]. c1 = 1100 ifTrue: [ x1_ 'C'. ]. c1 = 1101 ifTrue: [ x1_ 'D'. ]. c1 = 1110 ifTrue: [ x1_ 'E'. ]. c1 = 1111 ifTrue: [ x1_ 'F'. ]. n2_ x1. c1_ n3. c1 = 0000 ifTrue: [ x1_ 0. ]. c1 = 0001 ifTrue: [ x1_ 1. ]. c1 = 0010 ifTrue: [ x1_ 2. ]. c1 = 0011 ifTrue: [ x1_ 3. ]. c1 = 0100 ifTrue: [ x1_ 4. ]. c1 = 0101 ifTrue: [ x1_ 5. ]. c1 = 0110 ifTrue: [ x1_ 6. ]. c1 = 0111 ifTrue: [ x1_ 7. ]. c1 = 1000 ifTrue: [ x1_ 8. ]. c1 = 1001 ifTrue: [ x1_ 9. ]. c1 = 1010 ifTrue: [ x1_ 'A'. ]. c1 = 1011 ifTrue: [ x1_ 'B'. ]. c1 = 1100 ifTrue: [ x1_ 'C'. ]. c1 = 1101 ifTrue: [ x1_ 'D'. ]. c1 = 1110 ifTrue: [ x1_ 'E'. ]. c1 = 1111 ifTrue: [ x1_ 'F'. ]. n3_ x1. c1_ n4. c1 = 0000 ifTrue: [ x1_ 0. ]. c1 = 0001 ifTrue: [ x1_ 1. ]. c1 = 0010 ifTrue: [ x1_ 2. ]. c1 = 0011 ifTrue: [ x1_ 3. ]. c1 = 0100 ifTrue: [ x1_ 4. ]. c1 = 0101 ifTrue: [ x1_ 5. ]. c1 = 0110 ifTrue: [ x1_ 6. ]. c1 = 0111 ifTrue: [ x1_ 7. ]. c1 = 1000 ifTrue: [ x1_ 8. ]. c1 = 1001 ifTrue: [ x1_ 9. ]. c1 = 1010 ifTrue: [ x1_ 'A'. ]. c1 = 1011 ifTrue: [ x1_ 'B'. ]. c1 = 1100 ifTrue: [ x1_ 'C'. ]. c1 = 1101 ifTrue: [ x1_ 'D'. ]. c1 = 1110 ifTrue: [ x1_ 'E'. ]. c1 = 1111 ifTrue: [ x1_ 'F'. ]. n4_ x1. c1_ n5. c1 = 0000 ifTrue: [ x1_ 0. ]. c1 = 0001 ifTrue: [ x1_ 1. ]. c1 = 0010 ifTrue: [ x1_ 2. ]. c1 = 0011 ifTrue: [ x1_ 3. ]. c1 = 0100 ifTrue: [ x1_ 4. ]. c1 = 0101 ifTrue: [ x1_ 5. ]. c1 = 0110 ifTrue: [ x1_ 6. ]. c1 = 0111 ifTrue: [ x1_ 7. ]. c1 = 1000 ifTrue: [ x1_ 8. ]. c1 = 1001 ifTrue: [ x1_ 9. ]. c1 = 1010 ifTrue: [ x1_ 'A'. ]. c1 = 1011 ifTrue: [ x1_ 'B'. ]. c1 = 1100 ifTrue: [ x1_ 'C'. ]. c1 = 1101 ifTrue: [ x1_ 'D'. ]. c1 = 1110 ifTrue: [ x1_ 'E'. ]. c1 = 1111 ifTrue: [ x1_ 'F'. ]. n5_ x1. c1_ n6. c1 = 0000 ifTrue: [ x1_ 0. ]. c1 = 0001 ifTrue: [ x1_ 1. ]. c1 = 0010 ifTrue: [ x1_ 2. ]. c1 = 0011 ifTrue: [ x1_ 3. ]. c1 = 0100 ifTrue: [ x1_ 4. ]. c1 = 0101 ifTrue: [ x1_ 5. ]. c1 = 0110 ifTrue: [ x1_ 6. ]. c1 = 0111 ifTrue: [ x1_ 7. ]. c1 = 1000 ifTrue: [ x1_ 8. ]. c1 = 1001 ifTrue: [ x1_ 9. ]. c1 = 1010 ifTrue: [ x1_ 'A'. ]. c1 = 1011 ifTrue: [ x1_ 'B'. ]. c1 = 1100 ifTrue: [ x1_ 'C'. ]. c1 = 1101 ifTrue: [ x1_ 'D'. ]. c1 = 1110 ifTrue: [ x1_ 'E'. ]. c1 = 1111 ifTrue: [ x1_ 'F'. ]. n6_ x1. num_ '#'. num_ self concatenate: (num) with: (n1). num_ self concatenate: (num) with: (n2). num_ self concatenate: (num) with: (n3). num_ self concatenate: (num) with: (n4). num_ self concatenate: (num) with: (n5). num_ self concatenate: (num) with: (n6). ^ num
That works too...
EDIT: You can't make recursive custom blocks in Panther, right?
Last edited by ScratchReallyROCKS (2010-07-09 11:39:14)
Offline
ScratchReallyROCKS wrote:
You can't make recursive custom blocks in Panther, right?
I don't see why not -- Smalltalk is a real programming language, it allows recursion.
^ self foo x-1
or whatever.
EDIT: I guess technically it's not the block that's recursive, but rather the underlying method. So you could put a method named asHex in the Integer class and define it as (I'm guessing...)
self < 16
ifTrue: ^ '0123456789abcdef'[self].
ifFalse: ^ (self/16 floor asHex, '0123...def'[self mod 16])
Not being a Smalltalk programmer I just made up the notation for integer quotient, mod, and choosing a character from a string by index, but I'm pretty sure about the "^" part.
Last edited by bharvey (2010-07-09 13:23:25)
Offline
I was thinking about recursive non-method procedures when I received your email, and it turns out (as I told you) there is a way to do this:
factorial := [:x | x = 0 ifTrue: [1] ifFalse: [ x * (factorial value: x - 1)]]. factorial value: 3. "=> 6" factorial value: 5. "=> 120"
coming soon (AKA when I figure it out ) are unnamed recursive procedures
Last edited by nXIII (2010-07-09 18:04:18)
Offline
nXIII wrote:
I was thinking about recursive non-method procedures when I received your email, and it turns out (as I told you) there is a way to do this:
Code:
factorial := [:x | x = 0 ifTrue: [1] ifFalse: [ x * (factorial value: x - 1)]]. factorial value: 3. "=> 6" factorial value: 5. "=> 120"coming soon (AKA when I figure it out ) are unnamed recursive procedures
Hey! Did you see that Billybob-Mario made an online squeak VM? Ever think of a panther one?
Offline
nXIII wrote:
coming soon (AKA when I figure it out ) are unnamed recursive procedures
You're an amazing programmer and I'm hesitant to tell you there's anything you can't do, but I think actually this is one of them. You may well figure out how to have a recursive procedure without a global name, but there's no way a procedure can call itself without having a name for itself -- unless you just change the rules of discourse somehow so as to exclude from the term "name" a form of self-reference.
Figuring out how to write recursive procedures without a global naming mechanism is a key part of the Church numeral project on the BYOB web site.
Offline
When I show a Reporter block's stage monitor, it works fine - and then when I close it, I get this error thing from the System Browser. I can't show that stage monitor again until I do that stuff with a different Reporter block. My question: Will it be fixed in 1.1?
Last edited by Jonathanpb (2010-07-10 02:00:35)
Offline
Is the pitch block in 1.1?
Offline
| t2 t3 | (t1 = '') ifTrue:[^ false] t2 _ self numFileLines: (t1) asString. (t2 = '') ifTrue:[ t3 _ FileStream newFileNamed: t1. t3 close ].
spec:
make file $String$
type:
-
when I run this, it just hangs. Why?
Offline
Jonathanpb wrote:
When I show a Reporter block's stage monitor, it works fine - and then when I close it, I get this error thing from the System Browser. I can't show that stage monitor again until I do that stuff with a different Reporter block. My question: Will it be fixed in 1.1?
Im sure we're trying to fix it, its because nXIII edited the variables, you'll see if you reopen it in scratch (After renaming it .sb) you get this:
Before
After
I know you're talking about the watchers, but they're quite similar cases, the work very different in panther, but scratch bllocks are converted to panther blocks when you load a scratch project. I'm sure nXIII is working on fixing them.
Offline