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
On 25/09/2012 2:31 PM, 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?
Hi Hernan,
I don't think being ANSI-compatible should be a goal in any case. You won't find any Smalltalk flavor (commercial or Open Source) that is fully ANSI-compatible. All vendors have their extensions/exceptions/versions. Just have a look at Glorp to convince yourself of differences between Smalltalk implementations!
But if your goal is portability, I'd say you should start by having your code compatible with VAST, VW, Dolphin & Squeak. You'll probably cover most of other Smalltalks variants by doing so. The ANSI standard was never, to my knowledge, 100% fully respected by any Smalltalk vendor. Most of them tried to but none of them implemented it with 100% compliance. In other words, just do your best at satisfying compatibility with the most vendors.
This one uses Xtreams, the other one Nautilus browser or Zinc, the other one starts Array indices at 1, this other one does this, the other one does that, one uses Smalltalk while the other uses SmalltalkImage, etc.
Unfortunately, we're not in the Java world. You'll eventually need a Bundle/Application/Project/Package named "Portability" just like everyone else...
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
On 9/26/12, Levente Uzonyi leves@elte.hu 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
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
squeak-dev@lists.squeakfoundation.org