Article View: net.lang.pascal
Article #326Re: debug prints (was Re: Linear search again)
From: Chris Torek
Date: Sat, 09 Aug 1986 01:17
Date: Sat, 09 Aug 1986 01:17
39 lines
2206 bytes
2206 bytes
>In article <2785@umcp-cs.UUCP> I wrote:
[an example of how a Mesa programmer would probably write `find']:
>> find: PROC [ch: CHAR, string: LONG STRING]
>> RETURNS [pos: CARDINAL, found: BOOL];
>> BEGIN
>> FOR i:CARDINAL in [0..String.Length[string]] DO
>> IF string[i] = ch THEN RETURN [i, TRUE];
>> ENDLOOP;
>> RETURN [0, FALSE];
>> END;
In article <1174@umd5> zben@umd5.umd.edu (Ben Cranston) writes:
>I always avoided these nonstandard returns because they make it painful to
>drop in debug print statements. I would always slap in WRITELN(MYARGS) at
>the top, and WRITELN('Returning from FIND') at the bottom, and wonder why
>I never saw the 'Returning from FIND' output... If you are trying to find
>an infinite loop this can be really misleading.
Ah, but in Mesa, no one ever seems to use debug prints: for there is
a very complete debugger that is always accessible. For that matter,
if you did wish to wrap `find' with debug print statements, you could
simply rename the procedure to `findInternal' and add
-- Again, details may be wrong; all the manuals are four miles
-- away.
find: PROC [ch: CHAR, string: LONG STRING]
RETURNS [pos: CARDINAL, found: BOOL];
BEGIN
Msg.PutMsg["Enter find"L];
[pos, found] _ internalFind[ch, string];--`_' represents left-arrow
Msg.PutMsg["Exit find"L];
RETURN [pos, found];
END;
Indeed, this technique works in every language.
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1516)
UUCP: seismo!umcp-cs!chris
CSNet: chris@umcp-cs ARPA: chris@mimsy.umd.edu
Technical Details
Message-ID:
<2822@umcp-cs.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!watmath!clyde!caip!lll-crg!seismo!umcp-cs!chrisReferences:
<871@minster.UUCP> <2785@umcp-cs.UUCP> <1174@umd5>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!caip!lll-crg!seismo!umcp-cs!chris From: chris@umcp-cs.UUCP (Chris Torek) Newsgroups: net.lang.pascal Subject: Re: debug prints (was Re: Linear search again) Message-ID: <2822@umcp-cs.UUCP> Date: Fri, 8-Aug-86 21:17:35 EDT Article-I.D.: umcp-cs.2822 Posted: Fri Aug 8 21:17:35 1986 Date-Received: Sun, 10-Aug-86 20:07:26 EDT References: <871@minster.UUCP> <2785@umcp-cs.UUCP> <1174@umd5> Reply-To: chris@maryland.UUCP (Chris Torek) Organization: University of Maryland, Dept. of Computer Sci. Lines: 39