CONTENTS DELETED
The author has deleted this message.
|
It can be useful if you want to save some space in some very specific cases. You could have a one million strings 'hello' (hence one million objects) or deal transform them into symbols and have only one #hello. I recall a coworker telling me about this ultra-fast string search program in Gemstone where they transformed a gazillion duplicate strings into symbols thus using waaaaaaaay less memory and speeding up the lookup.
----------------- Benoît St-Jean Yahoo! Messenger: bstjean Twitter: @BenLeChialeux Pinterest: benoitstjean Instagram: Chef_Benito IRC: lamneth Blogue: endormitoire.wordpress.com "A standpoint is an intellectual horizon of radius zero". (A. Einstein) From: lb <[hidden email]> To: "[hidden email]" <[hidden email]> Sent: Friday, February 10, 2017 11:59 PM Subject: [Pharo-users] About asSymbol message , some questions in my mind Hi, I know Symbol is subclass of String. Any string object can become symbol object by sending 'asSymbol' message.. I think symbol must has its meaning in comon use, so the symbol should be composed of alphabet or number ‘without space“. BUT There are not compliant below 1. ' ' asSymbol >>>> no meaning 2. '$%%&' asSymbol >>>> no meaning 3. 'sign' asSymbol = 'sign ' asSymbol >>> false because of space. 3. ' one two three ' asSymbol >>> I think It should become three symbols = #one, #two, #three Maybe my understanding is wrong. Bing Liang |
In reply to this post by Bing Liang
Hi Bing,
Yes, any character is allowed in a Symbol. There is even special syntax that allows such Symbols to be represented literally. 'a b' asSymbol. => #'a b' Although it might be confusing, I don't see any problem. The concept of 'meaning' is defined by the user, the usage, not by the Symbol itself. A Symbol with a space cannot be a selector (message/method) name, but that does not mean a Symbol with a space could not be useful in some other context. Regards, Sven > On 11 Feb 2017, at 05:56, lb <[hidden email]> wrote: > > Hi, > I know Symbol is subclass of String. > Any string object can become symbol object by sending 'asSymbol' message.. > I think symbol must has its meaning in comon use, so the symbol should be composed of alphabet or number ‘without space“. > > BUT There are not compliant below > 1. ' ' asSymbol >>>> no meaning > 2. '$%%&' asSymbol >>>> no meaning > 3. 'sign' asSymbol = 'sign ' asSymbol >>> false because of space. > 3. ' one two three ' asSymbol >>> I think It should become three symbols = #one, #two, #three > > > Mybe my understanding is wrong. > > Bing Liang > > |
CONTENTS DELETED
The author has deleted this message.
|
> On 11 Feb 2017, at 09:41, lb <[hidden email]> wrote: > > Thank you, Sven > gradually clear. > 1. Symbol as String subclass, only guarantees a symbol object only one in system, use ==; > 2. keywords (selector name method name) are spectial symbols, without space or forbided characters; > 3. perform: aSymbol, means perform: aKeyword, > Should we add asKeyword to String, > let > perform: aString asKeyword > not > perform: aString asSymbol ? Good point, there has been discussion about a Selector class in the past, but I think the conclusion was, more or less, that it was not worth it (too much work/complexity for little gain). > Regards! > > Bing Liang > > At 2017-02-11 15:51:49, "Sven Van Caekenberghe" <[hidden email]> wrote: > >Hi Bing, > > > >Yes, any character is allowed in a Symbol. There is even special syntax that allows such Symbols to be represented literally. > > > >'a b' asSymbol. > > > > => #'a b' > > > >Although it might be confusing, I don't see any problem. > > > >The concept of 'meaning' is defined by the user, the usage, not by the Symbol itself. A Symbol with a space cannot be a selector (message/method) name, but that does not mean a Symbol with a space could not be useful in some other context. > > > >Regards, > > > >Sven > > > >> On 11 Feb 2017, at 05:56, lb <[hidden email]> wrote: > >> > >> Hi, > >> I know Symbol is subclass of String. > >> Any string object can become symbol object by sending 'asSymbol' message.. > >> I think symbol must has its meaning in comon use, so the symbol should be composed of alphabet or number ‘without space“. > >> > >> BUT There are not compliant below > >> 1. ' ' asSymbol >>>> no meaning > >> 2. '$%%&' asSymbol >>>> no meaning > >> 3. 'sign' asSymbol = 'sign ' asSymbol >>> false because of space. > >> 3. ' one two three ' asSymbol >>> I think It should become three symbols = #one, #two, #three > >> > >> > >> Mybe my understanding is wrong. > >> > >> Bing Liang > >> > >> > > > > > |
In reply to this post by Sven Van Caekenberghe-2
2017-02-11 8:51 GMT+01:00 Sven Van Caekenberghe <[hidden email]>: The concept of 'meaning' is defined by the user, the usage, not by the Symbol itself. A Symbol with a space cannot be a selector (message/method) name But it could be:
Only problem that we could not use them with normal syntax |
> On 11 Feb 2017, at 15:18, Denis Kudriashov <[hidden email]> wrote: > > > 2017-02-11 8:51 GMT+01:00 Sven Van Caekenberghe <[hidden email]>: > The concept of 'meaning' is defined by the user, the usage, not by the Symbol itself. A Symbol with a space cannot be a selector (message/method) name > > But it could be: > > Point methodDict at: #'name with space' put: Point>>#x. > > 2@3 perform: #'name with space' "==> 2" > > Only problem that we could not use them with normal syntax Cool. Or we could use any Unicode character, like icons and emoticons ;-) |
In reply to this post by Bing Liang
Hi Bing Liang,
Thanks for your comments. Fresh eyes provide interesting perspectives on things we take for granted. On Sat, Feb 11, 2017 at 4:41 PM, lb <[hidden email]> wrote: > Thank you, Sven > gradually clear. > 1. Symbol as String subclass, only guarantees a symbol object only one in > system, use ==; > 2. keywords (selector name method name) are spectial symbols, without space > or forbided characters; > 3. perform: aSymbol, means perform: aKeyword, Not exactly. It means perform a "message" where there are three types of messages... * unary, like #printString * binary, like #+ * keyword, like #perform: or #subclass:instanceVariableNames:classVariableNames:package: having a colon appended to each keyword > Should we add asKeyword to String, > let > perform: aString asKeyword or alternatively per above... perform: aString asMessage > not > perform: aString asSymbol ? In the case that aString contained a space, presumably #asMessage would produce a runtime error in asMessage whereas #asSymbol would produce a runtime error in #perform: I guess there is a minor benefit of failing early but will that make much difference in practice. Do you have a use case where it makes a major difference? > At 2017-02-11 15:51:49, "Sven Van Caekenberghe" <[hidden email]> wrote: >>Hi Bing, >> >>Yes, any character is allowed in a Symbol. There is even special syntax >> that allows such Symbols to be represented literally. >> >>'a b' asSymbol. >> >> => #'a b' >> >>Although it might be confusing, I don't see any problem. >> >>The concept of 'meaning' is defined by the user, the usage, not by the >> Symbol itself. A Symbol with a space cannot be a selector (message/method) >> name, but that does not mean a Symbol with a space could not be useful in >> some other context. >> >>> On 11 Feb 2017, at 05:56, lb <[hidden email]> wrote: >>> >>> Hi, >>> I know Symbol is subclass of String. >>> Any string object can become symbol object by sending 'asSymbol' >>> message.. >>> I think symbol must has its meaning in common use, so the symbol should >>> be composed of alphabet or number ‘without space“. Different domains have different common usage. IIUC, Smalltalk's definition of symbol is from the 1970s. Pharo is not overly constrained by Smalltalk traditions, but there must be sufficient gain to balance deviations from consistency with other Smalltalks. >>> >>> BUT There are not compliant below >>> 1. ' ' asSymbol >>>> no meaning >>> 2. '$%%&' asSymbol >>>> no meaning >>> 3. 'sign' asSymbol = 'sign ' asSymbol >>> false because of space. >>> 3. ' one two three ' asSymbol >>> I think It should >>> become three symbols = #one, #two, #three >>> >>> >>> Maybe my understanding is wrong. no problem. Being wrong is a great way to learn ;) cheers -ben |
On Sun, Feb 12, 2017 at 12:39 AM, Ben Coman <[hidden email]> wrote:
> Hi Bing Liang, > > Thanks for your comments. Fresh eyes provide interesting perspectives > on things we take for granted. > > On Sat, Feb 11, 2017 at 4:41 PM, lb <[hidden email]> wrote: >> Thank you, Sven >> gradually clear. >> 1. Symbol as String subclass, only guarantees a symbol object only one in >> system, use ==; >> 2. keywords (selector name method name) are spectial symbols, without space >> or forbided characters; >> 3. perform: aSymbol, means perform: aKeyword, > > Not exactly. It means perform a "message" where there are three types > of messages... > * unary, like #printString > * binary, like #+ > * keyword, like #perform: or > #subclass:instanceVariableNames:classVariableNames:package: > having a colon appended to each keyword > >> Should we add asKeyword to String, >> let >> perform: aString asKeyword > > or alternatively per above... perform: aString asMessage > >> not >> perform: aString asSymbol ? > > In the case that aString contained a space, > presumably #asMessage would produce a runtime error in asMessage > whereas #asSymbol would produce a runtime error in #perform: > I guess there is a minor benefit of failing early but will that make > much difference in practice. > Do you have a use case where it makes a major difference? > > >> At 2017-02-11 15:51:49, "Sven Van Caekenberghe" <[hidden email]> wrote: >>>Hi Bing, >>> >>>Yes, any character is allowed in a Symbol. There is even special syntax >>> that allows such Symbols to be represented literally. >>> >>>'a b' asSymbol. >>> >>> => #'a b' >>> >>>Although it might be confusing, I don't see any problem. >>> >>>The concept of 'meaning' is defined by the user, the usage, not by the >>> Symbol itself. A Symbol with a space cannot be a selector (message/method) >>> name, but that does not mean a Symbol with a space could not be useful in >>> some other context. >>> >>>> On 11 Feb 2017, at 05:56, lb <[hidden email]> wrote: >>>> >>>> Hi, >>>> I know Symbol is subclass of String. >>>> Any string object can become symbol object by sending 'asSymbol' >>>> message.. >>>> I think symbol must has its meaning in common use, so the symbol should >>>> be composed of alphabet or number ‘without space“. > > Different domains have different common usage. > IIUC, Smalltalk's definition of symbol is from the 1970s. > Pharo is not overly constrained by Smalltalk traditions, but there > must be sufficient gain to balance deviations from consistency with > other Smalltalks. > >>>> >>>> BUT There are not compliant below >>>> 1. ' ' asSymbol >>>> no meaning >>>> 2. '$%%&' asSymbol >>>> no meaning >>>> 3. 'sign' asSymbol = 'sign ' asSymbol >>> false because of space. >>>> 3. ' one two three ' asSymbol >>> I think It should >>>> become three symbols = #one, #two, #three >>>> >>>> >>>> Maybe my understanding is wrong. > > no problem. Being wrong is a great way to learn ;) > > cheers -ben P.S. Even wikipedia says "Symbols can contain whitespace (and all other characters)" https://en.wikipedia.org/wiki/Symbol_(programming) so it must be okay ;) cheers -ben |
In reply to this post by Ben Coman
CONTENTS DELETED
The author has deleted this message.
|
This post was updated on .
In reply to this post by Denis Kudriashov
CONTENTS DELETED
The author has deleted this message.
|
In reply to this post by Bing Liang
On Sun, Feb 12, 2017 at 10:54 AM, lb <[hidden email]> wrote:
> Hi Ben, > Thank you very much, your answer make me clear like water. > My question aimed on where, which type errors occur when perform a message. > My usecase. > when perform: aMessage(with a space), get DNU error , cannot find out by > eyes directly. What is the higher level use case? For example, are you getting input from a user that you evaluate as a command in some kind of Domain Specific Language? In such a case you may be better to validate the command has no spaces closer to the UI? > > asMessage is better than asSymbol. If you don't get community support for this, you can start extending String like this for your own projects and later promote your concrete experience with it. cheers -ben > > Cheers Bing > > At 2017-02-12 00:39:55, "Ben Coman" <[hidden email]> wrote: >>Hi Bing Liang, >> >>Thanks for your comments. Fresh eyes provide interesting perspectives >>on things we take for granted. >> >>On Sat, Feb 11, 2017 at 4:41 PM, lb <[hidden email]> wrote: >>> Thank you, Sven >>> gradually clear. >>> 1. Symbol as String subclass, only guarantees a symbol object only one in >>> system, use ==; >>> 2. keywords (selector name method name) are spectial symbols, without >>> space >>> or forbided characters; >>> 3. perform: aSymbol, means perform: aKeyword, >> >>Not exactly. It means perform a "message" where there are three types >>of messages... >>* unary, like #printString >>* binary, like #+ >>* keyword, like #perform: or >>#subclass:instanceVariableNames:classVariableNames:package: >>having a colon appended to each keyword >> >>> Should we add asKeyword to String, >>> let >>> perform: aString asKeyword >> >>or alternatively per above... perform: aString asMessage >> >>> not >>> perform: aString asSymbol ? >> >>In the case that aString contained a space, >>presumably #asMessage would produce a runtime error in asMessage >>whereas #asSymbol would produce a runtime error in #perform: >>I guess there is a minor benefit of failing early but will that make >>much difference in practice. >>Do you have a use case where it makes a major difference? >> >> >>> At 2017-02-11 15:51:49, "Sven Van Caekenberghe" <[hidden email]> wrote: >>>>Hi Bing, >>>> >>>>Yes, any character is allowed in a Symbol. There is even special syntax >>>> that allows such Symbols to be represented literally. >>>> >>>>'a b' asSymbol. >>>> >>>> => #'a b' >>>> >>>>Although it might be confusing, I don't see any problem. >>>> >>>>The concept of 'meaning' is defined by the user, the usage, not by the >>>> Symbol itself. A Symbol with a space cannot be a selector >>>> (message/method) >>>> name, but that does not mean a Symbol with a space could not be useful >>>> in >>>> some other context. >>>> >>>>> On 11 Feb 2017, at 05:56, lb <[hidden email]> wrote: >>>>> >>>>> Hi, >>>>> I know Symbol is subclass of String. >>>>> Any string object can become symbol object by sending 'asSymbol' >>>>> message.. >>>>> I think symbol must has its meaning in common use, so the symbol >>>>> should >>>>> be composed of alphabet or number ‘without space“. >> >>Different domains have different common usage. >>IIUC, Smalltalk's definition of symbol is from the 1970s. >>Pharo is not overly constrained by Smalltalk traditions, but there >>must be sufficient gain to balance deviations from consistency with >>other Smalltalks. >> >>>>> >>>>> BUT There are not compliant below >>>>> 1. ' ' asSymbol >>>> no meaning >>>>> 2. '$%%&' asSymbol >>>> no meaning >>>>> 3. 'sign' asSymbol = 'sign ' asSymbol >>> false because of space. >>>>> 3. ' one two three ' asSymbol >>> I think It should >>>>> become three symbols = #one, #two, #three >>>>> >>>>> >>>>> Maybe my understanding is wrong. >> >>no problem. Being wrong is a great way to learn ;) >> >>cheers -ben >> |
In reply to this post by Bing Liang
BUT There are not compliant below 1. ' ' asSymbol >>>> no meaning 2. '$%%&' asSymbol >>>> no meaning 3. 'sign' asSymbol = 'sign ' asSymbol >>> false because of space. 3. ' one two three ' asSymbol >>> I think It should become three symbols = #one, #two, #three I don't know what you mean by "no meaning', they're symbols. Try this in a Playground, it works in Pharo 5" | oc sym filtered| oc := ' one two three $%%&' splitOn: ' '. sym := OrderedCollection new. oc do: [:each | sym add: each asSymbol]. filtered := OrderedCollection new. filtered := sym select: [ :each | each ~= #'' ]. Transcript show: sym printString; cr. Transcript show: filtered printString; cr. On Fri, Feb 10, 2017 at 8:56 PM, lb <[hidden email]> wrote:
|
On 13 February 2017 at 13:48, lb <[hidden email]> wrote:
Hmm.. Then why it is so hard for you to comprehend such simple concept? In Chinese you have thousands unique glyphs, that you can use for writing, and each one has own meaning. Sometimes they literally mean something, but sometimes the meaning depends on context. That means that symbols '@#&%@#$' may not have meaning for most uses, while for some other can. This depends on context. Now if you take into account that in English, there's not so many glyphs for letter, so you have to use combination(s) of them to form words, phrases etc.. that could have meaning in specific context, while not have in other.
Best regards,
Igor Stasenko. |
Free forum by Nabble | Edit this page |