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! |
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 <[hidden email]> 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 > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners > Beginners mailing list [hidden email] 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! |
$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 <[hidden email]> 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 > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners > Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by calcrisk33
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_______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
>>>>> "Tobias" == Tobias Pape <[hidden email]> 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. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <[hidden email]> <URL:http://www.stonehenge.com/merlyn/> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.posterous.com/ for Smalltalk discussion _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by calcrisk33
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. _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
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:[hidden email] http://www.Keystone-Software.com _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by calcrisk33
a String in smalltalk: 'hello' aString in java : "hello" a Character in smalltalk : $h a character in java: 'h' Cheers Alain "calcrisk33" <[hidden email]> a écrit dans le message de news: [hidden email]... > 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 [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
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 <[hidden email]> wrote:
_______________________________________________ Beginners mailing list [hidden email] 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 <[hidden email]> 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:[hidden email] http://www.Keystone-Software.com _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Free forum by Nabble | Edit this page |