Transform sends to ANSI standard?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Transform sends to ANSI standard?

hernanmd

Hi folks,
I am rewriting packages to be compatible or more portable between
Smalltalks. Code Critics gives the following information on my packages:

- #cr, #crlf, #lf, #space, #tab, #findTokens:, ... are not part of the
ANSI string protocol.

- #cr and #lf are not part of the ANSI stream protocol.

- The ANSI standard does not support #asInteger and #asString on Object.

- Some collection methods are not ANSI compatible: #pairsDo:,
#collect:thenDo:, #reject:thenDo:, #detectSum:, #valuesDo:,
#keysSortedSafely, #new:withAll:, etc.

Does anyone have an idea on how to transform those sends to be ANSI
compatible?

Best regards,

Hernán

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [Pharo-project] Transform sends to ANSI standard?

Levente Uzonyi-2
On Tue, 25 Sep 2012, Hernán Morales Durand wrote:

>
> Hi folks,
> I am rewriting packages to be compatible or more portable between Smalltalks.
> Code Critics gives the following information on my packages:
>
> - #cr, #crlf, #lf, #space, #tab, #findTokens:, ... are not part of the ANSI
> string protocol.
>
> - #cr and #lf are not part of the ANSI stream protocol.
>
> - The ANSI standard does not support #asInteger and #asString on Object.
>
> - Some collection methods are not ANSI compatible: #pairsDo:,
> #collect:thenDo:, #reject:thenDo:, #detectSum:, #valuesDo:,
> #keysSortedSafely, #new:withAll:, etc.
>
> Does anyone have an idea on how to transform those sends to be ANSI
> compatible?
Is there an ANSI compatible Smalltalk implementation out there? I doubt
it. If I were you, then I'd use a compatibility layer like Sport or
Grease, instead of relying on the ANSI standard.

But to answer your question: you should check how these methods are
implemented and check if the implementation is ANSI compatible or not. In
most cases they are:

string cr ==> Character cr asString

#lf same as above

stream cr ==> stream nextPut: Character cr

#lf, #space, #tab similar to #cr

stream crlf ==> stream nextPut: Character cr; nextPut: Character lf

#findTokens: ==> no ANSI compatible method. If the argument is a single
character, then you can create a stream on the collection and use #upTo:
to find the parts.

collection collect: aBlock thenDo: anotherBlock ==> (collection collect: aBlock) do: anotherBlock

collection detectSum: aBlock ==> collection inject: 0 into: [ :sum :each | sum + (aBlock value: each) ]

#valuesDo: ==> use #do: or #keysAndValuesDo: instead

#keysSortedSafely ==> sorting is not part of the ANSI standard, only
SortedCollection is, so you can use something like: collection keys
asSortedCollection: [ :a :b | <copy the contents of the sort block here from #keysSortedSafely> ]

Array new: x withAll: y ==> (Array new: x) atAllPut: y


Levente

P.S.: My problem with the ANSI standard is that it seems more like
something that documents the common things in Smalltalks at the time of
its creation instead of a complete and future-proof base API.

>
> Best regards,
>
> Hernán
>
>
>
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: [Pharo-project] Transform sends to ANSI standard?

Hannes Hirzel
On 9/26/12, Levente Uzonyi <[hidden email]> wrote:

> On Tue, 25 Sep 2012, Hernán Morales Durand wrote:
>
>>
>> Hi folks,
>> I am rewriting packages to be compatible or more portable between
>> Smalltalks.
>> Code Critics gives the following information on my packages:
>>
>> - #cr, #crlf, #lf, #space, #tab, #findTokens:, ... are not part of the
>> ANSI
>> string protocol.
>>
>> - #cr and #lf are not part of the ANSI stream protocol.
>>
>> - The ANSI standard does not support #asInteger and #asString on Object.
>>
>> - Some collection methods are not ANSI compatible: #pairsDo:,
>> #collect:thenDo:, #reject:thenDo:, #detectSum:, #valuesDo:,
>> #keysSortedSafely, #new:withAll:, etc.
>>
>> Does anyone have an idea on how to transform those sends to be ANSI
>> compatible?
>
> Is there an ANSI compatible Smalltalk implementation out there? I doubt
> it. If I were you, then I'd use a compatibility layer like Sport or
> Grease, instead of relying on the ANSI standard.
>
> But to answer your question: you should check how these methods are
> implemented and check if the implementation is ANSI compatible or not. In
> most cases they are:
>
> string cr ==> Character cr asString
>
> #lf same as above
>
> stream cr ==> stream nextPut: Character cr
>
> #lf, #space, #tab similar to #cr
>
> stream crlf ==> stream nextPut: Character cr; nextPut: Character lf
>
> #findTokens: ==> no ANSI compatible method. If the argument is a single
> character, then you can create a stream on the collection and use #upTo:
> to find the parts.
>
> collection collect: aBlock thenDo: anotherBlock ==> (collection collect:
> aBlock) do: anotherBlock
>
> collection detectSum: aBlock ==> collection inject: 0 into: [ :sum :each |
> sum + (aBlock value: each) ]
>
> #valuesDo: ==> use #do: or #keysAndValuesDo: instead
>
> #keysSortedSafely ==> sorting is not part of the ANSI standard, only
> SortedCollection is, so you can use something like: collection keys
> asSortedCollection: [ :a :b | <copy the contents of the sort block here from
> #keysSortedSafely> ]
>
> Array new: x withAll: y ==> (Array new: x) atAllPut: y
>
>
> Levente
>
> P.S.: My problem with the ANSI standard is that it seems more like
> something that documents the common things in Smalltalks at the time of
> its creation instead of a complete and future-proof base API.
+1, in the 90ties.

The ANSI standard is not maintained.
http://www.smalltalk.org/versions/ANSIStandardSmalltalk.html

--Hannes


>
>>
>> Best regards,
>>
>> Hernán
>>
>>
>>

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: [Pharo-project] Transform sends to ANSI standard?

hernanmd
In reply to this post by Levente Uzonyi-2
Hi Levente,

On 26/09/2012 2:25, Levente Uzonyi wrote:

> On Tue, 25 Sep 2012, Hernán Morales Durand wrote:
>
>>
>> Hi folks,
>> I am rewriting packages to be compatible or more portable between
>> Smalltalks. Code Critics gives the following information on my packages:
>>
>> - #cr, #crlf, #lf, #space, #tab, #findTokens:, ... are not part of the
>> ANSI string protocol.
>>
>> - #cr and #lf are not part of the ANSI stream protocol.
>>
>> - The ANSI standard does not support #asInteger and #asString on Object.
>>
>> - Some collection methods are not ANSI compatible: #pairsDo:,
>> #collect:thenDo:, #reject:thenDo:, #detectSum:, #valuesDo:,
>> #keysSortedSafely, #new:withAll:, etc.
>>
>> Does anyone have an idea on how to transform those sends to be ANSI
>> compatible?
>
> Is there an ANSI compatible Smalltalk implementation out there? I doubt
> it. If I were you, then I'd use a compatibility layer like Sport or
> Grease, instead of relying on the ANSI standard.
>

Yes, for compatiblity I'm currently using Grease as much as I can. Read
my reply to Benoit about the ANSI Smalltalk.

> But to answer your question: you should check how these methods are
> implemented and check if the implementation is ANSI compatible or not.
> In most cases they are:
>
> string cr ==> Character cr asString
>
> #lf same as above
>
> stream cr ==> stream nextPut: Character cr
>
> #lf, #space, #tab similar to #cr
>
> stream crlf ==> stream nextPut: Character cr; nextPut: Character lf
>
> #findTokens: ==> no ANSI compatible method. If the argument is a single
> character, then you can create a stream on the collection and use #upTo:
> to find the parts.
>
> collection collect: aBlock thenDo: anotherBlock ==> (collection collect:
> aBlock) do: anotherBlock
>
> collection detectSum: aBlock ==> collection inject: 0 into: [ :sum :each
> | sum + (aBlock value: each) ]
>
> #valuesDo: ==> use #do: or #keysAndValuesDo: instead
>
> #keysSortedSafely ==> sorting is not part of the ANSI standard, only
> SortedCollection is, so you can use something like: collection keys
> asSortedCollection: [ :a :b | <copy the contents of the sort block here
> from #keysSortedSafely> ]
>
> Array new: x withAll: y ==> (Array new: x) atAllPut: y
>
>

This was what I wanted. Thanks for the tips, Levente.

Cheers,

Hernán


> Levente
>
> P.S.: My problem with the ANSI standard is that it seems more like
> something that documents the common things in Smalltalks at the time of
> its creation instead of a complete and future-proof base API.
>
>>
>> Best regards,
>>
>> Hernán
>>
>>
>>
>
>
>

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc