🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #468

Re: What I'd really like to see in an if-statement...

#468
From: Mike (I'll think of something ye...
Date: Mon, 14 Aug 1989 02:29
46 lines
2644 bytes
I've been following this, wondering if someone form the Icon group
would speak up. Since nobody has, and Karl came close to their
solution, I'll put an oar in...

In article <14278@haddock.ima.isc.com> karl@haddock.ima.isc.com (Karl Heuer) writes:
<Okay, then, here's one way to parse such constructs.  A comparison operator
<like "a < b" returns an object of an internal type "cascadable boolean", whose
<value is either {FALSE} or {TRUE, b}.  If a cascadable boolean is used in any
<context other than the left operand of a compare, it immediately decays
<into a normal boolean.  If it is the left operand of a compare, then
<"{FALSE} < c" returns {FALSE} (but should probably still evaluate c for side
<effects), while "{TRUE, b} < c" returns the same object as "b < c" (another
<cascadable boolean).

The Icon group find a slightly cleaner way to do this. Instead of
expression evalutaing to booleans, they either produce a value, or
"fail". Any expressions including a failed expression also fail, except
for "not" (which is classed as a control structure). If the expression
fed to not fails, then it returns a null value; otherwise, it fails.

Control constructs treat failed expressions as false, and valued
expressions as true. Relops are handled roughly as above, except that
where they return the value of the right-hand operand or fail. So that

	if a < b < c < d then

Will work as you'd expect - succeeding only if all the comparisons are
true. Likewise for:

	if a < b <= c = d < e then

etc, etc, etc.

I found this feature quite nice, and easy to work with. The concept of
"failure" also has interesting implications elsewhere, and works well
with the rest of the language.

The reference is "The Icon Programming Language", by Griswold &
Griswold. You can get Icon by ftp from several sites on the internet.

	<mike
--
Tell me how d'you get to be				Mike Meyer
As beautiful as that?					mwm@berkeley.edu
How did you get your mind				ucbvax!mwm
To tilt like your hat?					mwm@ucbjade.BITNET
Technical Details
Message-ID: <1989Aug14.022903.22953@agate.berkeley.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!network!ucsd!ucbvax!agate!usenet
References: <8577@batcomputer.tn.cornell.edu> <14251@haddock.ima.isc.com> <516@brazos.Rice.edu> <14278@haddock.ima.isc.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!network!ucsd!ucbvax!agate!usenet
From: mwm@eris.berkeley.edu (Mike (I'll think of something yet) Meyer)
Newsgroups: comp.lang.misc
Subject: Re: What I'd really like to see in an if-statement...
Message-ID: <1989Aug14.022903.22953@agate.berkeley.edu>
Date: 14 Aug 89 02:29:03 GMT
References: <8577@batcomputer.tn.cornell.edu> <14251@haddock.ima.isc.com> <516@brazos.Rice.edu> <14278@haddock.ima.isc.com>
Reply-To: mwm@eris.berkeley.edu (Mike (I'll think of something yet) Meyer)
Organization: Missionaria Phonibalonica
Lines: 46