- Feature Articles
- CodeSOD
- Error'd
-
Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Six things are readily apparent here.
In short, there's no way your comments aren't well-crafted jokes, and I bow to your intentionally hilarious mock ignorance.
Admin
Consider 7) bonus to the "six things" specific to your post. Almost like a global truth that actually needs no individual enumeration. Global - or "static", in Java/C# terms.
Admin
I hope this is a joke. otherwise AL = 0.5
Admin
Haha! I hope this is a joke and not meant to be a real solution. I guess it might make sense that Louisiana evaluates to 0.5
Admin
And what's even funnier is that I didn't even SEE this comment until AFTER I posted!
Admin
Doesn't work for "LA"
Admin
Nice try, this could terribly go wrong.
Admin
Louisiana screws that up:
f("LA") = 0.5
Admin
Nope. If you search for Louisiana, i.e., 'LA', you'll get 0.
Admin
TRWTF are all the people who think they're quite something for pointing out Larry's mistake, even though it was already spotted on page one, the third comment after Larry's.
Admin
Here's a solution in Ada.
United_States.ads:
Package United_States is -- States are enumerated by their name, with any spaces being replaced -- by underscores. Type State is ( Alabama, Alaska, Arizona, Arkansas, California, Colorado, Connecticut, Delaware, Florida, Georgia, Hawaii, Idaho, Illinois, Indiana, Iowa, Kansas, Kentucky, Louisiana, Maine, Maryland, Massachusetts, Michigan, Minnesota, Mississippi, Missouri, Montana, Nebraska, Nevada, New_Hampshire, New_Jersey, New_Mexico, New_York, North_Carolina, North_Dakota, Ohio, Oklahoma, Oregon, Pennsylvania, Rhode_Island, South_Carolina, South_Dakota, Tennessee, Texas, Utah, Vermont, Virginia, Washington, West_Virginia, Wisconsin, Wyoming ); -- Abbriviations are 2-character strings. SubType Abbriviation is String(1..2); -- State codes are abbriviations, there is a one-to-one relationship for -- abbriviations and state-names. -- Any change in the [number of] -- enumerations for States will force the compiler to reject this constant -- until the entries are reconciled. State_Code : Constant Array(State) of Abbriviation:= ( "AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY" ); -- The exception No_State will be raised if there is an attempt to get a -- State from an Abbriviation that is not a State code. No_State : Exception; -- Function To_State may raise No_State. Function To_State( Code : Abbriviation ) Return State; private -- We don't need no private portion for this! End United_States;United_States.adb:
With Ada.Strings.Maps.Constants; Use Ada.Strings.Maps; Package Body United_States is -- Apply takes a character mapping and applies it to a string. Function Apply( Str : String; Map : Character_Mapping ) Return String is begin -- We use the extended return syntax because the return-value is -- is unconstrained and all the information needed for constraint comes -- from the parameter itself. Return Result : String:= Str do For Index in Result'Range Loop Result(Index):= Value( Element => Result(Index), Map => Map ); end loop; End Return; end Apply; -- Returns a State when given an abbriviation, otherwise it raises No_State. Function To_State( Code : Abbriviation ) Return State is Use Ada.Strings.Maps; Map : Character_Mapping Renames Constants.Upper_Case_Map; This : Abbriviation:= Apply( Map => Map, Str => Code ); begin -- Search the State_Codes array for the given abbrivation. For Index in State_Code'Range loop if This = State_Code(Index) then Return Index; end if; end loop; -- The state was not found, so... Raise No_State; end To_State; End United_States;Admin
Admin
What strikes me is how similar ADA looks to VB. I think it could be extremely fruitful to create a cross-breed.
Admin
I do think a good RAD-IDE would be a nice addition to the available tools. I was thinking of writing one in Delphi; and if it were released as freeware [or perhaps shareware], would make a plausible alternative/addition to the few free Ada compilers/toolchains out there.
Admin
So, Alaska and Louisiana have the same index? Nice try, but no cigar.
Admin
Great, So Louisiana is 0.5
Admin
Admin
That's me among many. Larry's mistake is a featured comment while the correction isn't. Red flag to a bull.
Admin
Louisiana's index is 0.5?
Admin
Fails for 'LA', among others.