For Programmers: Free Programming Magazines  


Home > Archive > Smalltalk > April 2004 > Alternate code requested









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Alternate code requested
Mark Wilden

2004-04-02, 1:36 am

There's surely a better way to do this:

('abcdefghijklmnopqrstuvwxyz' at: x)


Michael Lucas-Smith

2004-04-02, 2:38 am


On 2-Apr-2004, "Mark Wilden" <mark@mwilden.com> wrote:

> There's surely a better way to do this:
>
> ('abcdefghijklmnopqrstuvwxyz' at: x)


($a asInteger + x) asCharacter
Andre Schnoor

2004-04-02, 4:47 am

> > There's surely a better way to do this:
>
> ($a asInteger + x) asCharacter


If the collection is graved in stone, located at one place only and limited
like in the example, then the original code is ok. If the collection changes
(e.g. different collating sequences) or is case insensitive or whatever,
then you should make it a class and do something like

myAlphabet at: x

Andre




Lex Spoon

2004-04-02, 4:35 pm

"Andre Schnoor" <andre.schnoor@web.de> writes:
>
> If the collection is graved in stone, located at one place only and limited
> like in the example, then the original code is ok. If the collection changes
> (e.g. different collating sequences) or is case insensitive or whatever,
> then you should make it a class and do something like
>
> myAlphabet at: x



This string is sometimes accessible as "Character alphabet" or
"String alphabet". Or if it's not in your dialect, no one will
be upset if you stick it there.

(Well, except for the people who want 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' :))



-Lex

Thomas Gagné

2004-04-03, 2:33 pm

Mark Wilden wrote:

> <snip>
>
>It turned out to be
>
> ($a asInteger + (x - 1)) asCharacter
>
>in Dolphin, at least.
>
>
>
>

A fairly reliable assumption that each letter of the alphabet will
proceed in order. Does Smalltalk guarantee such a thing?

--
..tom
remove email address' dashes for replies
opensource middleware at <http://isectd.sourceforge.net>
<http://gagne.homedns.org/~tgagne/>
Mark Wilden

2004-04-09, 11:33 pm

"Michael Lucas-Smith" <michaell@wizardis.NOSPAM.com.au> wrote in message
news:406d1157@news.totallyobjects.com...
>
> On 2-Apr-2004, "Mark Wilden" <mark@mwilden.com> wrote:
>
>
> ($a asInteger + x) asCharacter


It turned out to be

($a asInteger + (x - 1)) asCharacter

in Dolphin, at least.


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com