Hello everyone,
i'm learning Pharo and i'm having difficulties to understand the symbols, what are they? How are they different of the ByteString ? Why are they usefull ? Why should I put #string where I can put 'string' ? Thanks in advance for your answer. Valentin Ryckewaert |
A symbol is like a string, except that all symbols with the same value
are in fact the same object; that is, every #hello symbol is the exact same object as every other #hello symbol. See "identically equal" section here... http://sdmeta.gforge.inria.fr/FreeBooks/ByExample/08%20-%20Chapter%206%20-%20Special%20Symbol.pdf cheers, ben On Fri, Apr 8, 2016 at 7:20 AM, Valentin Ryckewaert <[hidden email]> wrote: > Hello everyone, > > i'm learning Pharo and i'm having difficulties to understand the symbols, > what are they? How are they different of the ByteString ? Why are they > usefull ? > Why should I put #string where I can put 'string' ? > > Thanks in advance for your answer. > Valentin Ryckewaert |
As a result, internal names (e.g., method names) are usually symbols.
Strings are normally used for string manipulation, symbols for unambiguous (but humanly readable!) internal reference (vulgo 'naming'). Markus On 08/04/16 10:53, Ben Coman wrote: > A symbol is like a string, except that all symbols with the same value > are in fact the same object; that is, every #hello symbol is the exact > same object as every other #hello symbol. > > See "identically equal" section here... > http://sdmeta.gforge.inria.fr/FreeBooks/ByExample/08%20-%20Chapter%206%20-%20Special%20Symbol.pdf > > cheers, ben > > On Fri, Apr 8, 2016 at 7:20 AM, Valentin Ryckewaert > <[hidden email]> wrote: >> Hello everyone, >> >> i'm learning Pharo and i'm having difficulties to understand the symbols, >> what are they? How are they different of the ByteString ? Why are they >> usefull ? >> Why should I put #string where I can put 'string' ? >> >> Thanks in advance for your answer. >> Valentin Ryckewaert > |
And symbols are immutable
Brad Sent from my iPad > On Apr 7, 2016, at 9:41 PM, Markus Stumptner <[hidden email]> wrote: > > As a result, internal names (e.g., method names) are usually symbols. Strings are normally used for string manipulation, symbols for unambiguous (but humanly readable!) internal reference (vulgo 'naming'). > > Markus > > >> On 08/04/16 10:53, Ben Coman wrote: >> A symbol is like a string, except that all symbols with the same value >> are in fact the same object; that is, every #hello symbol is the exact >> same object as every other #hello symbol. >> >> See "identically equal" section here... >> http://sdmeta.gforge.inria.fr/FreeBooks/ByExample/08%20-%20Chapter%206%20-%20Special%20Symbol.pdf >> >> cheers, ben >> >> On Fri, Apr 8, 2016 at 7:20 AM, Valentin Ryckewaert >> <[hidden email]> wrote: >>> Hello everyone, >>> >>> i'm learning Pharo and i'm having difficulties to understand the symbols, >>> what are they? How are they different of the ByteString ? Why are they >>> usefull ? >>> Why should I put #string where I can put 'string' ? >>> >>> Thanks in advance for your answer. >>> Valentin Ryckewaert > >
Brad Selfridge
|
In reply to this post by Valentin Ryckewaert
On Friday, 8 April 2016, Valentin Ryckewaert <[hidden email]> wrote: Hi, As the others said, symbols are some kind of string that are unique in the image. I would like to talk also about a super cool feature. A Block can receive the message #value:. For example when you do a #do: on a collection, the block will receive multiple #value: message with the element in argument. [ :class | class allSubclasses] value: Object. And the cool feature is that Symbol also have this method, so with the polymorphism you can do: #AllSubclasses value: Object { Object . Morph . Integer . Float } collect: #allSubclasses This is a pretty cool feature that I wanted to share.
-- Cheers Cyril Ferlicot |
In reply to this post by Ben Coman
| s1 s2 |
s1 := 1234 asString. s2 := 1234 asString. s1 = s2. "true" s1 == s2. "false" s1 asSymbol = s2 asSymbol. "true" s1 asSymbol == s2 asSymbol. "true" (s1 class allInstances select: [:s | s = s1 ]) size. "2" (s1 asSymbol class allInstances select: [:s | s = s1 asSymbol ]) size. "1" [ #stringA = #stringB ] bench. "26,812,864 per second" [ 'StringA' = 'StringB' ] bench. "3,492,987 per second" Best regards, Henrik -----Original Message----- From: Pharo-users [mailto:[hidden email]] On Behalf Of Ben Coman Sent: Friday, April 8, 2016 3:23 AM To: Any question about pharo is welcome <[hidden email]> Subject: Re: [Pharo-users] Pharo-users Question about the symbols A symbol is like a string, except that all symbols with the same value are in fact the same object; that is, every #hello symbol is the exact same object as every other #hello symbol. See "identically equal" section here... http://sdmeta.gforge.inria.fr/FreeBooks/ByExample/08%20-%20Chapter%206%20-%20Special%20Symbol.pdf cheers, ben On Fri, Apr 8, 2016 at 7:20 AM, Valentin Ryckewaert <[hidden email]> wrote: > Hello everyone, > > i'm learning Pharo and i'm having difficulties to understand the > symbols, what are they? How are they different of the ByteString ? Why > are they usefull ? > Why should I put #string where I can put 'string' ? > > Thanks in advance for your answer. > Valentin Ryckewaert |
Henrik Nergaard <[hidden email]> writes:
> | s1 s2 | > > s1 := 1234 asString. > s2 := 1234 asString. > > s1 = s2. "true" > s1 == s2. "false" > > s1 asSymbol = s2 asSymbol. "true" > s1 asSymbol == s2 asSymbol. "true" > > (s1 class allInstances select: [:s | s = s1 ]) size. "2" > (s1 asSymbol class allInstances select: [:s | s = s1 asSymbol ]) size. "1" > > [ #stringA = #stringB ] bench. "26,812,864 per second" > [ 'StringA' = 'StringB' ] bench. "3,492,987 per second" very very nice summary. -- Damien Cassou http://damiencassou.seasidehosting.st "Success is the ability to go from one failure to another without losing enthusiasm." --Winston Churchill |
> On 08 Apr 2016, at 09:19, Damien Cassou <[hidden email]> wrote: > > Henrik Nergaard <[hidden email]> writes: > >> | s1 s2 | >> >> s1 := 1234 asString. >> s2 := 1234 asString. >> >> s1 = s2. "true" >> s1 == s2. "false" >> >> s1 asSymbol = s2 asSymbol. "true" >> s1 asSymbol == s2 asSymbol. "true" >> >> (s1 class allInstances select: [:s | s = s1 ]) size. "2" >> (s1 asSymbol class allInstances select: [:s | s = s1 asSymbol ]) size. "1" >> >> [ #stringA = #stringB ] bench. "26,812,864 per second" >> [ 'StringA' = 'StringB' ] bench. "3,492,987 per second" > > very very nice summary. YES! > -- > Damien Cassou > http://damiencassou.seasidehosting.st > > "Success is the ability to go from one failure to another without > losing enthusiasm." --Winston Churchill |
In reply to this post by Damien Cassou-2
+1
>> | s1 s2 | >> >> s1 := 1234 asString. >> s2 := 1234 asString. >> >> s1 = s2. "true" >> s1 == s2. "false" >> >> s1 asSymbol = s2 asSymbol. "true" >> s1 asSymbol == s2 asSymbol. "true" >> >> (s1 class allInstances select: [:s | s = s1 ]) size. "2" >> (s1 asSymbol class allInstances select: [:s | s = s1 asSymbol ]) size. "1" >> >> [ #stringA = #stringB ] bench. "26,812,864 per second" >> [ 'StringA' = 'StringB' ] bench. "3,492,987 per second" > very very nice summary. > |
In reply to this post by Henrik Nergaard
On 08/04/2016 09:05, Henrik Nergaard wrote: > | s1 s2 | > > s1 := 1234 asString. > s2 := 1234 asString. > > s1 = s2. "true" > s1 == s2. "false" > > s1 asSymbol = s2 asSymbol. "true" > s1 asSymbol == s2 asSymbol. "true" > > (s1 class allInstances select: [:s | s = s1 ]) size. "2" > (s1 asSymbol class allInstances select: [:s | s = s1 asSymbol ]) size. "1" > > [ #stringA = #stringB ] bench. "26,812,864 per second" > [ 'StringA' = 'StringB' ] bench. "3,492,987 per second" > > Best regards, > Henrik The class comment of Symbol is really not enough. It need improvement. I think it would be good to add your examples at least in the class comment. -- Cyril Ferlicot http://www.synectique.eu 165 Avenue Bretagne Lille 59000 France signature.asc (817 bytes) Download Attachment |
Good idea!
Stef Le 8/4/16 09:49, Cyril Ferlicot Delbecque a écrit : > > On 08/04/2016 09:05, Henrik Nergaard wrote: >> | s1 s2 | >> >> s1 := 1234 asString. >> s2 := 1234 asString. >> >> s1 = s2. "true" >> s1 == s2. "false" >> >> s1 asSymbol = s2 asSymbol. "true" >> s1 asSymbol == s2 asSymbol. "true" >> >> (s1 class allInstances select: [:s | s = s1 ]) size. "2" >> (s1 asSymbol class allInstances select: [:s | s = s1 asSymbol ]) size. "1" >> >> [ #stringA = #stringB ] bench. "26,812,864 per second" >> [ 'StringA' = 'StringB' ] bench. "3,492,987 per second" >> >> Best regards, >> Henrik > Hi Henrik, > > The class comment of Symbol is really not enough. It need improvement. I > think it would be good to add your examples at least in the class comment. > |
Free forum by Nabble | Edit this page |