🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #1639

Re: Proposed Enhancement to select/case (yes, I know...)

#1639
From: Karl Heuer
Date: Wed, 05 Sep 1990 00:27
42 lines
2672 bytes
In article <13719@smoke.BRL.MIL> gwyn@smoke.BRL.MIL (Doug Gwyn) writes:
>In article <MEISSNER.90Aug31102441@osf.osf.org> meissner@osf.org (Michael Meissner) writes:
>>... one of the problems that kept being mentioned was 'a'..'z'
>
>That's not a problem, is it?  The only sane meaning would be the numbers from
>'a' through 'z', however many there may be...  That fact that that particular
>code would probably not correctly achieve the programmer's intention is the
>programmer's problem, not the language's.

Well put.

There are two reasons why 'a'..'z' might not be the right answer: (a) the
alphabet isn't contiguous (e.g. EBCDIC) or (b) the locale doesn't use English.

Objection (a) is valid, but may plausibly be countered with "I don't care
about oddball machines like that".  For many programs, it simply isn't worth
the effort to make them strictly conforming%.  Besides which, preprocessor
conditionals may have already established the alphabet, thus making the use
portable:
	#if _X_ASCII
	#define LOWER 'a'..'z'
	#endif
	#if _X_EBCDIC /* need case lists as well as ranges */
	#define LOWER 'a'..'i','j'..'r','s'..'z'
	#endif
	... switch (ch) ... case LOWER: ...

Objection (b) doesn't necessarily apply.  If the program is processing natural
language text, then islower() is certainly better&.  But I think it's more
likely (in the world of existing programs commonly found on Unix systems) that
it's processing some flavor of computer language: for example, ed(1) has
exactly 26 mark registers in any locale, doesn't it?

Karl W. Z. Heuer (karl@kelp.ima.isc.com or ima!kelp!karl), The Walking Lint
________
% Lots of people don't bother to cast pointers before handing them to a
  prototypeless free(); this fails on word-addressible architectures, which is
  probably a more likely situation than non-ASCII.  One's complement is my
  personal bugaboo; I have no idea how much of my code it would break.
& Even this is probably the wrong answer: islower() tests the *union* of the
  English alphabet and the locale's alphabet; islower('w') tests true even in
  a country where 'w' is not a letter.
Technical Details
Message-ID: <17628@haddock.ima.isc.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!watmath!att!ima!haddock!karl
References: <1990Aug30.164610.3519@zoo.toronto.edu> <13714@smoke.BRL.MIL> <MEISSNER.90Aug31102441@osf.osf.org> <13719@smoke.BRL.MIL>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!watmath!att!ima!haddock!karl
From: karl@haddock.ima.isc.com (Karl Heuer)
Newsgroups: comp.std.c
Subject: Re: Proposed Enhancement to select/case (yes, I know...)
Message-ID: <17628@haddock.ima.isc.com>
Date: 5 Sep 90 00:27:09 GMT
References: <1990Aug30.164610.3519@zoo.toronto.edu> <13714@smoke.BRL.MIL> <MEISSNER.90Aug31102441@osf.osf.org> <13719@smoke.BRL.MIL>
Reply-To: karl@kelp.ima.isc.com (Karl Heuer)
Organization: Interactive Systems, Cambridge, MA 02138-5302
Lines: 42