Subject: Re: Questions... I am new to scheme
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 1998/12/09
Newsgroups: comp.lang.scheme
Message-ID: <74krbo$1fidg@fido.engr.sgi.com>
Barry Margolin  <barmar@bbnplanet.com> wrote:
+---------------
| Shriram Krishnamurthi  <shriram@cs.rice.edu> wrote:
| >This gets stranger by the minute.  Pray tell why
| >  (+ 'catbox) ==> 'catbox
| >is "fine".
| 
| It doesn't violate the specification (which does not mandate type
| checking), and it could be considered better than
| 
| (+ 'catbox) ==> Core dump or General Protection Violation
+---------------

But that's not what SIOD would have done with it. If the code hadn't
excessively optimized the one-arg case, you'd have gotten the same
perfectly-acceptable [if a bit terse] error you get with any other
domain error in SIOD:

	> (+ 1 'two)
	ERROR: wta(2nd) to plus (errobj two)
	> 

[where "wta" == "wrong type of argument"]:

The offending source code is here [note that since "plus" is defined
with init_subr_2n("+",plus), "eval" will fold args for it -- an implicit
"reduce" in CL terms].

	LISP plus(LISP x,LISP y)
	{if NULLP(y)
	   return(NULLP(x) ? flocons(0) : x);
	 if NFLONUMP(x) err("wta(1st) to plus",x);
	 if NFLONUMP(y) err("wta(2nd) to plus",y);
	 return(flocons(FLONM(x) + FLONM(y)));}

Oooh! Do you see what I see? It's even worse! Looky what happens
in *these* cases!  ;-}  ;-}

	> (+)		; this one's o.k.
	0
	> (+ '())	; ??? Doesn't even return ()!!
	0
	> (+ '() '())	; ??!?!?!
	0
	> (+ '()  '() '() '() '() '() '() )
	0
	> 


-Rob

p.s. Here's a fix (untested) which shouldn't run much slower,
if anyone cares:

	LISP plus(LISP x,LISP y)
	{if NULLP(y)
	  {if NULLP(x)
	     return flocons(0);
	   else
	     {if NFLONUMP(x) err("wta(1st) to plus",x);   /*BUGFIX*/
	      return x;}}
	 if NFLONUMP(x) err("wta(1st) to plus",x);
	 if NFLONUMP(y) err("wta(2nd) to plus",y);
	 return(flocons(FLONM(x) + FLONM(y)));}

-----
Rob Warnock, 8L-855		rpw3@sgi.com
Applied Networking		http://reality.sgi.com/rpw3/
Silicon Graphics, Inc.		Phone: 650-933-1673
2011 N. Shoreline Blvd.		FAX: 650-964-0811
Mountain View, CA  94043	PP-ASEL-IA