Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!eru!luth!sunic!mcsun!ukc!edcastle!aiai!jeff From: jeff@aiai.ed.ac.uk (Jeff Dalton) Newsgroups: comp.lang.prolog Subject: Re: logic programs -> procedural lang? Keywords: Prolog, typing, compiler efficiency Message-ID: <1229@skye.ed.ac.uk> Date: 13 Oct 89 16:36:13 GMT References: <27335@shemp.CS.UCLA.EDU> <869@gamera.cs.utexas.edu> <979@skye.ed.ac.uk> <2367@munnari.oz.au> Reply-To: jeff@aiai.UUCP (Jeff Dalton) Organization: AIAI, University of Edinburgh, Scotland Lines: 60 In article <2367@munnari.oz.au> ok@cs.mu.oz.au (Richard O'Keefe) writes: > In article <2181@munnari.oz.au> ok@cs.mu.oz.au I claimed that > (defun app (A Z) (if (endp A) Z (cons (car A) (app (cdr A) Z)))) > would check three times that A is a list. >In article <979@skye.ed.ac.uk>, jeff@aiai.ed.ac.uk (Jeff Dalton) writes: >> Richard, I've seen this claim before (in Warren's paper, for example), >> and I've always been a bit puzzled by it. >Why be puzzled by it? David Warren and I were both used to Lisp systems >(in my case Interlisp-D) that do in fact make the check that many times. >Admittedly, Interlisp-D does the check in microcode, but then the Prolog >equivalent is in microcode on the Xerox Lisp machines too. People at >RMIT in Melbourne use Common Lisp on MacIvory, and I would be surprised >if that Lisp system didn't repeat the check three times as part of the >three instructions involved. The Lisp system I use here from time to >time definitely has the check repeated in CAR and CDR -- I just checked. >(ok, ok, so it's a Scheme, not a Lisp, big deal.) Microcoded Lisp machines, and other special hardware, tend to make lots of type checks because it doesn't cost very much. On "conventional" machines, most Lisps make such checks in compiled code only if the code was compiled in some sort of "safe" mode. Even you have used at least one Lisp in Edinburgh (Franz Lisp) that makes only one check in compiled code. If you want to know what Lisp does (so that you can makew true statements about it), you have to look at the practice in a number of different implementations. >> However, in many Lisps there's only one check because the compiled >> code for a car or cdr never includes a check. It's fair to flame Lisp, >> or at least some Lisp implementations, for being less safe. >Now that is a serious mistake. Consider those broken Lisp implementations >(but not the ones I've used or the one David Warren used) duly flamed. No one says you have to like the way Lisp works. That it can be unsafe is a valid complaint. In practice, however, the lack of checks is usually a manageable problem. If you want to be safer, you can define some pattern-matching macros that arrange for cars and cdrs to be taken only when the object is known to be a cons. >> But I don't think it's fair to say Lisp makes three checks, >> because it doesn't. >It _was_ fair for me to say that, because every Lisp I'd personally checked >DOES make the three checks. Well, how many did you check? If I check one or two Prologs, am I then justified in making unqualified statements about Prolog as if my observations were true in general? >So what I *should* have said is that "a naive Lisp compiler which makes >the checks which are necessary for safety will do more checking than a >naive Prolog compiler which makes the checks which are necessary for safety". Right. Cheers, Jeff