home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!spool.mu.edu!agate!anarres.CS.Berkeley.EDU!bh
- From: bh@anarres.CS.Berkeley.EDU (Brian Harvey)
- Newsgroups: comp.lang.scheme
- Subject: Re: applying or
- Date: 25 Dec 1992 23:50:39 GMT
- Organization: University of California, Berkeley
- Lines: 30
- Message-ID: <1hg6ofINN7ev@agate.berkeley.edu>
- References: <BztJDI.1J1@malihh.hanse.de> <BztyDu.KDE@cs.psu.edu>
- NNTP-Posting-Host: anarres.cs.berkeley.edu
-
- One reason AND and OR are special forms is so that you can have one
- clause that checks the validity of another, e.g.,
-
- (and (not (zero? num)) (> (/ 1 num) 7))
-
- If AND were an ordinary procedure, Scheme would evaluate both argument
- expressions before invoking the procedure, so it would try to divide by
- zero before noticing that it's supposed to avoid the second clause in
- that case.
-
-
- Another reason is just efficiency. If you see an expression like
-
- (or (= 2 (+ 1 1)) (prime? 184893479827823480745907830796137))
-
- you can save a lot of time by noticing that the first clause is true.
-
-
- Of course, you *could* do this sort of computation even if AND and OR were
- ordinary procedures, by avoiding AND and OR and using IF instead in such
- cases. But this way is deemed more aesthetically pleasing.
-
-
- I think it would be nice if the standard specified that AND and OR are
- *also* ordinary procedures, so they could be mapped over lists and so on.
- The standard recommends against, but allows, the use of keywords as
- symbols other than in the car of an expression. I would change this to
- allow the overloading but prebind all such symbols to procedures that
- do the same as the special form. (I wouldn't really care except for the
- exercise in The Book that expects you to map cons-stream over a matrix.)
-