Given:
| binnum index bool| binnum := 'abc'. index := 1. bool:=(binnum at: index). (bool = 'a') ifTrue: [Transcript show: 'ifTrue'; cr] ifFalse: [Transcript show: 'ifFalse'; cr]. Transcript show: bool; cr.
Why does this result in:
ifFalse a
and not
ifTrue a
I've tried both = and == with no success.
Any help is much appreciated!
-- View this message in context: http://forum.world.st/ifTrue-ifFalse-help-tp3477318p3477318.html Sent from the Squeak - Beginners mailing list archive at Nabble.com.
try
bool = $a
to get what you expect. A String consists of Characters (Character is a separate class).
You could also do
'abc' inspect
to see what's going on :)
Cheers
Matthias
On Wed, Apr 27, 2011 at 08:05, calcrisk33 rick.m.wallace@gmail.com wrote:
Given:
| binnum index bool| binnum := 'abc'. index := 1. bool:=(binnum at: index). (bool = 'a') ifTrue: [Transcript show: 'ifTrue'; cr] ifFalse: [Transcript show: 'ifFalse'; cr]. Transcript show: bool; cr.
Why does this result in:
ifFalse a
and not
ifTrue a
I've tried both = and == with no success.
Any help is much appreciated!
-- View this message in context: http://forum.world.st/ifTrue-ifFalse-help-tp3477318p3477318.html Sent from the Squeak - Beginners mailing list archive at Nabble.com. _______________________________________________ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
bool = $a worked like a charm! So what exactly does $ do? I'm more familiar with Java and am trying to break that thought process... relating Squeak to Java.
Appreciate it!
-- View this message in context: http://forum.world.st/ifTrue-ifFalse-help-tp3477318p3477352.html Sent from the Squeak - Beginners mailing list archive at Nabble.com.
$a is a way to input the Character "a". Just like you use 'Hello' to input the string "Hello". In other words, it is a Character literal.
Does that make sense?
Matthias
On Wed, Apr 27, 2011 at 08:35, calcrisk33 rick.m.wallace@gmail.com wrote:
bool = $a worked like a charm! So what exactly does $ do? I'm more familiar with Java and am trying to break that thought process... relating Squeak to Java.
Appreciate it!
-- View this message in context: http://forum.world.st/ifTrue-ifFalse-help-tp3477318p3477352.html Sent from the Squeak - Beginners mailing list archive at Nabble.com. _______________________________________________ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
Am 2011-04-27 um 08:35 schrieb calcrisk33:
bool = $a worked like a charm! So what exactly does $ do? I'm more familiar with Java and am trying to break that thought process... relating Squeak to Java.
Note that Java has not notion of first-class Characters. Every character is just a string of the length 1 (just like you used it in the first place).
Think of a Smalltalk string as a collection of characters, then, if you break it apart (with #index: or likewise), you'll get Characters back.
So Long, -Tobias
"Tobias" == Tobias Pape Das.Linux@gmx.de writes:
Tobias> Every character is just a string of the length 1 (just like you Tobias> used it in the first place).
Not really.
That would imply $a is 'a'. And it's very much not, which is what the OP is discovering.
calcrisk33 pisze:
bool = $a worked like a charm! So what exactly does $ do? I'm more familiar with Java and am trying to break that thought process... relating Squeak to Java.
Appreciate it!
Some analogies:
If you know C: Smalltalk|C 'abc' |"abc" $a |'a'
If you know some philosophy:
compare the relations: is a kind of is a part of or compare sets in set theoretical and mereological meaning (in mereological meaning {a}=a)
If you know some linguistics: compare count nouns with mass nouns
If you know nothing about those: compare: half of a car isn't a car half litre of water is water
is a character a string? in Smalltalk the answer is NO.
On Wed, 27 Apr 2011 18:06:29 +0200, Mateusz Grotek
is a character a string? in Smalltalk the answer is NO.
But of course in Smalltalk you can have a string with only one character in it. But:
$a is not equal to 'a' $a is equal to 'a' first or 'a' at: 1.
Having a Character class in Smalltalk is valuable because there are messages one might want to send to a character that wouldn't make sense sending to a string, even one of length 1.
Lou ----------------------------------------------------------- Louis LaBrunda Keystone Software Corp. SkypeMe callto://PhotonDemon mailto:Lou@Keystone-Software.com http://www.Keystone-Software.com
a String in smalltalk: 'hello' aString in java : "hello" a Character in smalltalk : $h a character in java: 'h'
Cheers Alain
"calcrisk33" rick.m.wallace@gmail.com a écrit dans le message de news: 1303886113281-3477352.post@n4.nabble.com...
bool = $a worked like a charm! So what exactly does $ do? I'm more familiar with Java and am trying to break that thought process... relating Squeak to Java.
Appreciate it!
-- View this message in context: http://forum.world.st/ifTrue-ifFalse-help-tp3477318p3477352.html Sent from the Squeak - Beginners mailing list archive at Nabble.com.
Thanks for all the feedback and analogies to Java. In addition to the original question...
Given: | a b c | a := 6 // 2. b := a asCharacter. c := b isMemberOf: Character. Transcript show: 'Member of Char: ', c, ' b = ', b; cr.
Result: Member of Char: true b =
I was wondering why b is not getting displayed.
Thanks in advance!
On Wed, Apr 27, 2011 at 4:39 PM, Alain_Rastoul alr.dev@free.fr wrote:
a String in smalltalk: 'hello' aString in java : "hello" a Character in smalltalk : $h a character in java: 'h'
Cheers Alain
"calcrisk33" rick.m.wallace@gmail.com a écrit dans le message de news: 1303886113281-3477352.post@n4.nabble.com...
bool = $a worked like a charm! So what exactly does $ do? I'm more familiar with Java and am trying to break that thought process... relating Squeak to Java.
Appreciate it!
-- View this message in context: http://forum.world.st/ifTrue-ifFalse-help-tp3477318p3477352.html Sent from the Squeak - Beginners mailing list archive at Nabble.com.
Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
Hi Rick,
6 // 2 results in an integer value of 3. 3 asCharacter results in a character with a value of 3 but that is not the printable character of $3 which has an integer value of 51. Try sending #inspect (like: 3 asCharacter inspect) to objects, it should help you see what/how things are stored.
Lou
On Thu, 28 Apr 2011 09:26:34 -0400, Richard Wallace rick.m.wallace@gmail.com wrote:
Thanks for all the feedback and analogies to Java. In addition to the original question...
Given: | a b c | a := 6 // 2. b := a asCharacter. c := b isMemberOf: Character. Transcript show: 'Member of Char: ', c, ' b = ', b; cr.
Result: Member of Char: true b =
I was wondering why b is not getting displayed.
Thanks in advance!
----------------------------------------------------------- Louis LaBrunda Keystone Software Corp. SkypeMe callto://PhotonDemon mailto:Lou@Keystone-Software.com http://www.Keystone-Software.com
beginners@lists.squeakfoundation.org