Path: utzoo!mnetor!uunet!husc6!think!barmar From: barmar@think.COM (Barry Margolin) Newsgroups: comp.lang.lisp Subject: Re: Correctness (was Re: Common Lisp lacks portability) Message-ID: <13975@think.UUCP> Date: 18 Dec 87 20:55:21 GMT References: <1421@orstcs.CS.ORST.EDU> <233@spt.entity.com> <2126@ulowell.cs.ulowell.edu> <5208@sol.ARPA> <1547@orstcs.CS.ORST.EDU> <859@rocky.STANFORD.EDU> Sender: usenet@think.UUCP Reply-To: barmar@sauron.think.com.UUCP (Barry Margolin) Organization: Thinking Machines Corporation, Cambridge, MA Lines: 52 In article <859@rocky.STANFORD.EDU> andy@rocky.UUCP (Andy Freeman) writes: >The original program was something like > >(defun silly (a b) > (declare (integer a b)) > (loop i from a to b do (print i))) Actually, I think he said that the program was something like (defun silly (a b) (sloop for i from a to b do (print i))) and the SLOOP macro expands into code that contains somwething like (declare (integer i a b)), but it doesn't check whether A and B actually are integers at runtime. Something is incorrect here, the question is whether it is SILLY or SLOOP, and it depends on SLOOP's documentation. If the documentation for the FROM/TO keyword says "the arguments must evaluate to integers" then it becomes SILLY's responsibility to check its arguments. If the documentation doesn't say this then SLOOP should include type-checking code in its expansion or should expand into code that doesn't assume a particular type. >Silly does not handle illegal input - its definition promises that >its input is well-formed. Safe-silly handles illegal input. [omitted] >This is the same sort of thing one must do in every language. >For example, one must test input to pascal programs. [I don't >feel like explaining this so insert more sarcasm here.] Well, yes and no. In traditional Algol-derived languages the compiler will not let you pass incorrect data types. The type of all expressions can be determined at compile time, the types of arguments expected by subroutines are declared, so argument type checking can be done. You can't execute a Pascal program in which a floating point value is passed to a routine expecting an integer. If you have argument constraints that go beyond what the language's type grammar allows you to specify (for example, if a routine requires that its argument be an even integer) then you are correct that the routine must do its own input checking. However, since the type specification doesn't let you say this, it is not a case of a redundant check. --- Barry Margolin Thinking Machines Corp. barmar@think.com seismo!think!barmar