Pharo-users Question about the symbols
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-%2... cheers, ben On Fri, Apr 8, 2016 at 7:20 AM, Valentin Ryckewaert <valentin.ryckewaert@gmail.com> 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-%2...
cheers, ben
On Fri, Apr 8, 2016 at 7:20 AM, Valentin Ryckewaert <valentin.ryckewaert@gmail.com> 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 <mst@cs.unisa.edu.au> 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-%2...
cheers, ben
On Fri, Apr 8, 2016 at 7:20 AM, Valentin Ryckewaert <valentin.ryckewaert@gmail.com> 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
| 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:pharo-users-bounces@lists.pharo.org] On Behalf Of Ben Coman Sent: Friday, April 8, 2016 3:23 AM To: Any question about pharo is welcome <pharo-users@lists.pharo.org> 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-%2... cheers, ben On Fri, Apr 8, 2016 at 7:20 AM, Valentin Ryckewaert <valentin.ryckewaert@gmail.com> 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 <henrik.nergaard@uia.no> 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 <damien.cassou@inria.fr> wrote:
Henrik Nergaard <henrik.nergaard@uia.no> 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
+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.
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. -- Cyril Ferlicot http://www.synectique.eu 165 Avenue Bretagne Lille 59000 France
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.
On Friday, 8 April 2016, Valentin Ryckewaert <valentin.ryckewaert@gmail.com> 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' ?
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.
Thanks in advance for your answer. Valentin Ryckewaert
-- Cheers Cyril Ferlicot
participants (10)
-
Ben Coman -
Brad Selfridge -
Cyril Ferlicot -
Cyril Ferlicot Delbecque -
Damien Cassou -
Henrik Nergaard -
Markus Stumptner -
stepharo -
Sven Van Caekenberghe -
Valentin Ryckewaert