Article View: comp.lang.misc
Article #3563Re: Run-time Type Errors in Smalltalk
From: Barry Margolin
Date: Wed, 17 Apr 1991 20:20
Date: Wed, 17 Apr 1991 20:20
38 lines
1968 bytes
1968 bytes
In article <2023@optima.cs.arizona.edu> gudeman@cs.arizona.edu (David Gudeman) writes:
>What can you say about errors that occur in production code in
>dynamically typed languages? First, they are not caused by the
>necessity of getting around the static type checker. Second, they are
>almost never type errors of the sort that could have been caught by a
>static type checker. Third, if they are type errors they cannot cause
>a core dump or other unpredictable behavior.
The above assumes that a dynamically typed language always does type
checking. Common Lisp, for instance, does not require runtime type
checking. The following has unpredictable behavior:
(rplaca (read) 3)
If the input does not contain the representation of a cons then it has
undefined behavior, and can core dump, corrupt the Lisp image, or launch a
nuke.
A static type checker could flag this as a potential type error, but it
shouldn't disallow the code. If the input is coming from the user I'd
consider the above to be poor code, but if it is coming from a
machine-generated source that is "guaranteed" to have the representation of
a cons, then it is safe; for instance, the following is fine:
(with-input-from-string (*standard-input* (format nil "(~S)" object))
(rplaca (read) 3))
is guaranteed to return the same thing as
(list 3)
or signal a read-error if OBJECT doesn't have a readable printed
representation.
--
Barry Margolin, Thinking Machines Corp.
barmar@think.com
{uunet,harvard}!think!barmar
Technical Details
Message-ID:
<1991Apr17.202034.13268@Think.COM>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!think.com!barmarReferences:
<2023@optima.cs.arizona.edu>Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.misc Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!think.com!barmar From: barmar@think.com (Barry Margolin) Subject: Re: Run-time Type Errors in Smalltalk Message-ID: <1991Apr17.202034.13268@Think.COM> Sender: news@Think.COM Organization: Thinking Machines Corporation, Cambridge MA, USA References: <2023@optima.cs.arizona.edu> Date: Wed, 17 Apr 91 20:20:34 GMT