[M3devel] quake and/or "short circuit"

Jay K jay.krell at cornell.edu
Wed Aug 18 03:17:02 CEST 2010


I don't know what the names should be, I'm pretty comfortable with "&&" and "||".
Short circuiting is very useful.
 
> Dijkstra advises against it, though.

That makes me question Dijkstra, not short circuiting.
 
 
Also useful is assignment being an expression.
I wish it was in Modula-3.
 
Such things as:
 
 
if ((f = fopen(..)) && fread(f,...)
 
 
or if (p && *p)
 
 
In the first case Modula-3 forces useless verbosity and indentation.
In the second case Modula-3 gets it right but Quake fails.
 
Lacking these features you end up contorting your code one way or another, such as duplicating things.
 
 
I really can't stand code that looks like:
 
 
result = do something
   if success(result)
   do more stuff
   if success
      do more stuff
      if succes
        do more stuff
 
 
Modula-3 this wrong.
Exceptions help.
But basically I want to be able to introduce WITH or VAR anywhere, but not need to "END" them, and therefore no implied need for indentation..
 
 - Jay

 
> To: jay.krell at cornell.edu
> Date: Tue, 17 Aug 2010 15:27:04 -0700
> From: mika at async.async.caltech.edu
> CC: m3devel at elegosoft.com
> Subject: Re: [M3devel] quake and/or "short circuit"
> 
> If you really want it, you can always introduce "cand" and "cor" for
> the short-circuit versions.
> 
> Dijkstra advises against it, though.
> 
> Mika
> 
> Jay K writes:
> >--_203e0ef7-c6fc-42ed-ad8c-3abbdc3b9c9e_
> >Content-Type: text/plain; charset="iso-8859-1"
> >Content-Transfer-Encoding: quoted-printable
> >
> >
> >It would have been nice for and/or to short circuit in quake like they do i=
> >n C.
> >
> >
> >Code like:
> >
> >if not defined("TARGET")
> > readonly TARGET =3D "I386_FREEBSD"
> >else
> > if not equal(TARGET=2C "FreeBSD4")
> > readonly TARGET =3D "I386_FREEBSD"
> > end
> >end
> >
> >
> >is better written as:
> >if not defined("TARGET") or not equal(TARGET=2C "FreeBSD4")
> > readonly TARGET =3D "I386_FREEBSD"
> >end
> >
> >but that isn't allowed because equal() will complain that TARGET isn't defi=
> >ned.
> >
> >It probably can't fixed though=2C due to e.g.:
> >
> >if TRUE or DoSomething()
> > ...
> >end
> >
> >
> >would be broken.
> >
> >
> >perhaps
> >OR and AND
> >or short_circuit_and
> >or and_shorted
> >or and_short_circuit
> >or and_early_out
> >or and_early
> >or "&&"
> >or something...
> >
> >
> >Or I should just rewrite so much quake in Modula-3...
> >
> >
> > - Jay
> > =
> >
> >--_203e0ef7-c6fc-42ed-ad8c-3abbdc3b9c9e_
> >Content-Type: text/html; charset="iso-8859-1"
> >Content-Transfer-Encoding: quoted-printable
> >
> ><html>
> ><head>
> ><style><!--
> >.hmmessage P
> >{
> >margin:0px=3B
> >padding:0px
> >}
> >body.hmmessage
> >{
> >font-size: 10pt=3B
> >font-family:Tahoma
> >}
> >--></style>
> ></head>
> ><body class=3D'hmmessage'>
> >It would have been nice for and/or to short circuit in quake like they do i=
> >n C.<br><br><br>Code like:<br><br>if not defined("TARGET")<br>&nbsp=3B read=
> >only TARGET =3D "I386_FREEBSD"<br>else<br>&nbsp=3B if not equal(TARGET=2C "=
> >FreeBSD4")<br>&nbsp=3B&nbsp=3B&nbsp=3B readonly TARGET =3D "I386_FREEBSD"<b=
> >r>&nbsp=3B end<br>end<br><br><br>is better written as:<br>if not defined("T=
> >ARGET") or not equal(TARGET=2C "FreeBSD4")<br>&nbsp=3B readonly TARGET =3D =
> >"I386_FREEBSD"<br>end<br><br>but that isn't allowed because equal() will co=
> >mplain that TARGET isn't defined.<br><br>It probably can't fixed though=2C =
> >due to e.g.:<br><br>if TRUE or DoSomething()<br>&nbsp=3B ...<br>end<br><br>=
> ><br>would be broken.<br><br><br>perhaps<br>OR and AND<br>or short_circuit_a=
> >nd<br>or and_shorted<br>or and_short_circuit<br>or and_early_out<br>or and_=
> >early<br>or "&amp=3B&amp=3B"<br>or something...<br><br><br>Or I should just=
> > rewrite so much quake in Modula-3...<br><br><br>&nbsp=3B- Jay<br> 
> > =
> > </body>
> ></html>=
> >
> >--_203e0ef7-c6fc-42ed-ad8c-3abbdc3b9c9e_--
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20100818/8676e06b/attachment-0002.html>


More information about the M3devel mailing list