Path: utzoo!utgpu!attcan!uunet!tut.cis.ohio-state.edu!mailrus!cornell!uw-beaver!uw-june!pattis
From: pattis@june.cs.washington.edu (Richard Pattis)
Newsgroups: comp.lang.misc
Subject: Re: VAR vs. IN/OUT
Summary: Binary Search Subprograms and Parameter Modes
Message-ID: <8997@june.cs.washington.edu>
Date: 11 Aug 89 23:50:16 GMT
References: <173@enea.se>
Organization: U of Washington, Computer Science, Seattle
Lines: 24

I published an article in SIGCSE Volume 20, Number 1 (February 1988) that
surveyed 40 CS-1/CS-2 books that used Pascal as their language of discourse.
Of those books that included a subprogram for binary searching, 50% passed
the parameter as non-VAR.  Thus, the running times of all these subprograms
was really O(N) not O(Log N) for all Pascal compilers I know; in fact, some
programs were recursive, which increased their running time to O(N Log N).
Similarly, the space requirements we also increased by this amount.

  In Ada (most compilers I know) parameter transmission is O(1), regardless
of the parameter mode.  The use of a correct parameter mode is subject to
static semantic rules.  A student cannot accidentally omit VAR and then find
that the actual parameter matching this formal remains unchanged after the
subprogram call.  Such inconsistent uses of Ada parameter modes are detected
and reported by Ada compilers.

  The equivalent of Pascal's non-VAR mode (which is rarely needed) can be
accomplished in Ada by declaring a local object and initializing it to the
value of an IN parameter (most useful for nonrecursive traversing of linked
data structures).

  Finally, Modula-3 and Turing each allow a "constant" (I think) parameter
mode that matches the semantics of Ada's IN mode.

Rich Pattis