[Pharo-project] Unicode depending on Zinc
Hi, Does this method make sense? (Do we want Unicode to update itself?) Unicode class>>initializeCaseMappings "Unicode initializeCaseMappings" ToCasefold := IdentityDictionary new. ToUpper := IdentityDictionary new. ToLower := IdentityDictionary new. UIManager default informUserDuring: [ :bar| | result | bar value: 'Downloading Unicode data'. (result := ZnClient get: ' http://www.unicode.org/Public/UNIDATA/CaseFolding.txt') isSuccess ifFalse: [ ^ self error: 'Download failed' ]. bar value: 'Updating Case Mappings'. self parseCaseMappingFrom: result contents readStream ]. Guille
What about changing the initialize via a request to a method with the data? I don't think Unicode case mappings will change too much in time :P... Something like the attach Guille On Wed, Mar 14, 2012 at 12:06 PM, Guillermo Polito < guillermopolito@gmail.com> wrote:
Hi,
Does this method make sense? (Do we want Unicode to update itself?)
Unicode class>>initializeCaseMappings "Unicode initializeCaseMappings" ToCasefold := IdentityDictionary new. ToUpper := IdentityDictionary new. ToLower := IdentityDictionary new. UIManager default informUserDuring: [ :bar| | result | bar value: 'Downloading Unicode data'. (result := ZnClient get: ' http://www.unicode.org/Public/UNIDATA/CaseFolding.txt') isSuccess ifFalse: [ ^ self error: 'Download failed' ]. bar value: 'Updating Case Mappings'. self parseCaseMappingFrom: result contents readStream ].
Guille
Of course with a nice comment saying something like: "Initialize the mappings from unicode lower to upper case and vice versa. sourceCodes and destinyCodes contains the unicode values for the mappings, and they match one by one. The source of this mapping can be found at: http://www.unicode.org/Public/UNIDATA/CaseFolding.txt' " On Thu, Mar 15, 2012 at 12:22 PM, Guillermo Polito < guillermopolito@gmail.com> wrote:
What about changing the initialize via a request to a method with the data? I don't think Unicode case mappings will change too much in time :P...
Something like the attach
Guille
On Wed, Mar 14, 2012 at 12:06 PM, Guillermo Polito < guillermopolito@gmail.com> wrote:
Hi,
Does this method make sense? (Do we want Unicode to update itself?)
Unicode class>>initializeCaseMappings "Unicode initializeCaseMappings" ToCasefold := IdentityDictionary new. ToUpper := IdentityDictionary new. ToLower := IdentityDictionary new. UIManager default informUserDuring: [ :bar| | result | bar value: 'Downloading Unicode data'. (result := ZnClient get: ' http://www.unicode.org/Public/UNIDATA/CaseFolding.txt') isSuccess ifFalse: [ ^ self error: 'Download failed' ]. bar value: 'Updating Case Mappings'. self parseCaseMappingFrom: result contents readStream ].
Guille
Hi Guillermo, On 15 Mar 2012, at 16:25, Guillermo Polito wrote:
Of course with a nice comment saying something like:
"Initialize the mappings from unicode lower to upper case and vice versa. sourceCodes and destinyCodes contains the unicode values for the mappings, and they match one by one. The source of this mapping can be found at: http://www.unicode.org/Public/UNIDATA/CaseFolding.txt' "
Have a look at what I did with http://code.google.com/p/pharo/issues/detail?id=4187 The spec tables are constants, like in your latest example, but I added a method that can generate these from an internet accessible resource (using Zn as HTTP client). That way, there is some kind of dependency, but not really at run time. I think it is cool to literally use these public spec documents. Sven
But what if I want to have an image without Zinc? Ok, I will not use that method, but I'll get an Undeclared entry and therefore a dirty image... :/ On Thu, Mar 15, 2012 at 12:37 PM, Sven Van Caekenberghe <sven@beta9.be>wrote:
Hi Guillermo,
On 15 Mar 2012, at 16:25, Guillermo Polito wrote:
Of course with a nice comment saying something like:
"Initialize the mappings from unicode lower to upper case and vice versa. sourceCodes and destinyCodes contains the unicode values for the mappings, and they match one by one. The source of this mapping can be found at: http://www.unicode.org/Public/UNIDATA/CaseFolding.txt' "
Have a look at what I did with http://code.google.com/p/pharo/issues/detail?id=4187
The spec tables are constants, like in your latest example, but I added a method that can generate these from an internet accessible resource (using Zn as HTTP client). That way, there is some kind of dependency, but not really at run time. I think it is cool to literally use these public spec documents.
Sven
That's why I generated a method from the file, and then put the link in the comment... On Thu, Mar 15, 2012 at 8:17 PM, Guillermo Polito <guillermopolito@gmail.com
wrote:
But what if I want to have an image without Zinc? Ok, I will not use that method, but I'll get an Undeclared entry and therefore a dirty image... :/
On Thu, Mar 15, 2012 at 12:37 PM, Sven Van Caekenberghe <sven@beta9.be>wrote:
Hi Guillermo,
On 15 Mar 2012, at 16:25, Guillermo Polito wrote:
Of course with a nice comment saying something like:
"Initialize the mappings from unicode lower to upper case and vice versa. sourceCodes and destinyCodes contains the unicode values for the mappings, and they match one by one. The source of this mapping can be found at: http://www.unicode.org/Public/UNIDATA/CaseFolding.txt' "
Have a look at what I did with http://code.google.com/p/pharo/issues/detail?id=4187
The spec tables are constants, like in your latest example, but I added a method that can generate these from an internet accessible resource (using Zn as HTTP client). That way, there is some kind of dependency, but not really at run time. I think it is cool to literally use these public spec documents.
Sven
you can always make dependency less hardcoded: Smalltalk at: #ZnClient ifAbsent: [ self error: 'sorry dude' ] ifPresent: [:client | ... download stuff , whatever ] On 16 March 2012 00:18, Guillermo Polito <guillermopolito@gmail.com> wrote:
That's why I generated a method from the file, and then put the link in the comment...
On Thu, Mar 15, 2012 at 8:17 PM, Guillermo Polito <guillermopolito@gmail.com> wrote:
But what if I want to have an image without Zinc? Ok, I will not use that method, but I'll get an Undeclared entry and therefore a dirty image... :/
On Thu, Mar 15, 2012 at 12:37 PM, Sven Van Caekenberghe <sven@beta9.be> wrote:
Hi Guillermo,
On 15 Mar 2012, at 16:25, Guillermo Polito wrote:
Of course with a nice comment saying something like:
"Initialize the mappings from unicode lower to upper case and vice versa. Â sourceCodes and destinyCodes contains the unicode values for the mappings, and they match one by one. The source of this mapping can be found at: http://www.unicode.org/Public/UNIDATA/CaseFolding.txt' "
Have a look at what I did with http://code.google.com/p/pharo/issues/detail?id=4187
The spec tables are constants, like in your latest example, but I added a method that can generate these from an internet accessible resource (using Zn as HTTP client). That way, there is some kind of dependency, but not really at run time. I think it is cool to literally use these public spec documents.
Sven
-- Best regards, Igor Stasenko.
If you want to avoid hardcoding a class reference to Zn, you could do a simple download like this: 'http://zn.stfx.eu/zn/numbers.txt' asZnUrl retrieveContents It avoids an entry to Undeclared or the ugly test, and it since it is implemented as retrieveContents "Download and return the resource that I refer to. This will typically return a String or a ByteArray (see ZnClient>>#get:). If something goes wrong, an exception will be signalled." " 'http://zn.stfx.eu/zn/numbers.txt' asZnUrl retrieveContents. " ^ ZnClient new beOneShot; enforceHttpSuccess: true; get: self it is easy to use for simple scripting. Sven On 16 Mar 2012, at 00:24, Igor Stasenko wrote:
you can always make dependency less hardcoded:
Smalltalk at: #ZnClient ifAbsent: [ self error: 'sorry dude' ] ifPresent: [:client | ... download stuff , whatever ]
On 16 March 2012 00:18, Guillermo Polito <guillermopolito@gmail.com> wrote:
That's why I generated a method from the file, and then put the link in the comment...
On Thu, Mar 15, 2012 at 8:17 PM, Guillermo Polito <guillermopolito@gmail.com> wrote:
But what if I want to have an image without Zinc? Ok, I will not use that method, but I'll get an Undeclared entry and therefore a dirty image... :/
On Thu, Mar 15, 2012 at 12:37 PM, Sven Van Caekenberghe <sven@beta9.be> wrote:
Hi Guillermo,
On 15 Mar 2012, at 16:25, Guillermo Polito wrote:
Of course with a nice comment saying something like:
"Initialize the mappings from unicode lower to upper case and vice versa. sourceCodes and destinyCodes contains the unicode values for the mappings, and they match one by one. The source of this mapping can be found at: http://www.unicode.org/Public/UNIDATA/CaseFolding.txt' "
Have a look at what I did with http://code.google.com/p/pharo/issues/detail?id=4187
The spec tables are constants, like in your latest example, but I added a method that can generate these from an internet accessible resource (using Zn as HTTP client). That way, there is some kind of dependency, but not really at run time. I think it is cool to literally use these public spec documents.
Sven
On Mar 16, 2012, at 11:49 AM, Sven Van Caekenberghe wrote:
If you want to avoid hardcoding a class reference to Zn, you could do a simple download like this:
'http://zn.stfx.eu/zn/numbers.txt' asZnUrl retrieveContents
Sven the problem is that it just hides the problem. If Zinc is not loaded then this code is broken code. Stef
It avoids an entry to Undeclared or the ugly test, and it since it is implemented as
retrieveContents "Download and return the resource that I refer to. This will typically return a String or a ByteArray (see ZnClient>>#get:). If something goes wrong, an exception will be signalled."
" 'http://zn.stfx.eu/zn/numbers.txt' asZnUrl retrieveContents. "
^ ZnClient new beOneShot; enforceHttpSuccess: true; get: self
it is easy to use for simple scripting.
Sven
On 16 Mar 2012, at 00:24, Igor Stasenko wrote:
you can always make dependency less hardcoded:
Smalltalk at: #ZnClient ifAbsent: [ self error: 'sorry dude' ] ifPresent: [:client | ... download stuff , whatever ]
On 16 March 2012 00:18, Guillermo Polito <guillermopolito@gmail.com> wrote:
That's why I generated a method from the file, and then put the link in the comment...
On Thu, Mar 15, 2012 at 8:17 PM, Guillermo Polito <guillermopolito@gmail.com> wrote:
But what if I want to have an image without Zinc? Ok, I will not use that method, but I'll get an Undeclared entry and therefore a dirty image... :/
On Thu, Mar 15, 2012 at 12:37 PM, Sven Van Caekenberghe <sven@beta9.be> wrote:
Hi Guillermo,
On 15 Mar 2012, at 16:25, Guillermo Polito wrote:
Of course with a nice comment saying something like:
"Initialize the mappings from unicode lower to upper case and vice versa. sourceCodes and destinyCodes contains the unicode values for the mappings, and they match one by one. The source of this mapping can be found at: http://www.unicode.org/Public/UNIDATA/CaseFolding.txt' "
Have a look at what I did with http://code.google.com/p/pharo/issues/detail?id=4187
The spec tables are constants, like in your latest example, but I added a method that can generate these from an internet accessible resource (using Zn as HTTP client). That way, there is some kind of dependency, but not really at run time. I think it is cool to literally use these public spec documents.
Sven
On 16 Mar 2012, at 12:15, Stéphane Ducasse wrote:
Sven the problem is that it just hides the problem. If Zinc is not loaded then this code is broken code.
I know ;-) My last answer was to the question of how to avoid 'hardcoding a reference'. My first answer was: add a method that can generate another method with constant data (since the spec doesn't change often anyway, but it is cool to show in code that you derived the constants from a spec).
Sven the problem is that it just hides the problem.
If Zinc is not loaded then this code is broken code.
I know ;-)
My last answer was to the question of how to avoid 'hardcoding a reference'.
My first answer was: add a method that can generate another method with constant data (since the spec doesn't change often anyway, but it is cool to show in code that you derived the constants from a spec).
Yes Stef
I would prefer to have a method that contains this data. Because any Smalltalk at:â¦. will lead to dead code when ring is not loaded. Stef On Mar 16, 2012, at 12:18 AM, Guillermo Polito wrote:
That's why I generated a method from the file, and then put the link in the comment...
On Thu, Mar 15, 2012 at 8:17 PM, Guillermo Polito <guillermopolito@gmail.com> wrote: But what if I want to have an image without Zinc? Ok, I will not use that method, but I'll get an Undeclared entry and therefore a dirty image... :/
On Thu, Mar 15, 2012 at 12:37 PM, Sven Van Caekenberghe <sven@beta9.be> wrote: Hi Guillermo,
On 15 Mar 2012, at 16:25, Guillermo Polito wrote:
Of course with a nice comment saying something like:
"Initialize the mappings from unicode lower to upper case and vice versa. sourceCodes and destinyCodes contains the unicode values for the mappings, and they match one by one. The source of this mapping can be found at: http://www.unicode.org/Public/UNIDATA/CaseFolding.txt' "
Have a look at what I did with http://code.google.com/p/pharo/issues/detail?id=4187
The spec tables are constants, like in your latest example, but I added a method that can generate these from an internet accessible resource (using Zn as HTTP client). That way, there is some kind of dependency, but not really at run time. I think it is cool to literally use these public spec documents.
Sven
Add a bug entry :) Stef On Mar 15, 2012, at 4:22 PM, Guillermo Polito wrote:
What about changing the initialize via a request to a method with the data? I don't think Unicode case mappings will change too much in time :P...
Something like the attach
Guille
On Wed, Mar 14, 2012 at 12:06 PM, Guillermo Polito <guillermopolito@gmail.com> wrote: Hi,
Does this method make sense? (Do we want Unicode to update itself?)
Unicode class>>initializeCaseMappings "Unicode initializeCaseMappings" ToCasefold := IdentityDictionary new. ToUpper := IdentityDictionary new. ToLower := IdentityDictionary new. UIManager default informUserDuring: [ :bar| | result | bar value: 'Downloading Unicode data'. (result := ZnClient get: 'http://www.unicode.org/Public/UNIDATA/CaseFolding.txt') isSuccess ifFalse: [ ^ self error: 'Download failed' ]. bar value: 'Updating Case Mappings'. self parseCaseMappingFrom: result contents readStream ].
Guille
<Unicode class-initializeCaseMapping.st>
goes! :) http://code.google.com/p/pharo/issues/detail?id=5484&thanks=5484&ts=13318257... On Thu, Mar 15, 2012 at 12:29 PM, Stéphane Ducasse < stephane.ducasse@inria.fr> wrote:
Add a bug entry :)
Stef
On Mar 15, 2012, at 4:22 PM, Guillermo Polito wrote:
What about changing the initialize via a request to a method with the data? I don't think Unicode case mappings will change too much in time :P...
Something like the attach
Guille
On Wed, Mar 14, 2012 at 12:06 PM, Guillermo Polito < guillermopolito@gmail.com> wrote: Hi,
Does this method make sense? (Do we want Unicode to update itself?)
Unicode class>>initializeCaseMappings "Unicode initializeCaseMappings" ToCasefold := IdentityDictionary new. ToUpper := IdentityDictionary new. ToLower := IdentityDictionary new. UIManager default informUserDuring: [ :bar| | result | bar value: 'Downloading Unicode data'. (result := ZnClient get: ' http://www.unicode.org/Public/UNIDATA/CaseFolding.txt') isSuccess ifFalse: [ ^ self error: 'Download failed' ]. bar value: 'Updating Case Mappings'. self parseCaseMappingFrom: result contents readStream ].
Guille
<Unicode class-initializeCaseMapping.st>
participants (4)
-
Guillermo Polito -
Igor Stasenko -
Stéphane Ducasse -
Sven Van Caekenberghe