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: <74ljqp$1c73g@fido.engr.sgi.com>
Ben Goetter <goetter@angrygraycat.com.xyz> wrote:
+---------------
| rpw3@rigden.engr.sgi.com says...
| > 	> (+ '())	; ??? Doesn't even return ()!!
| > 	0
| 
| Another SIOD pun: empty list == unbound variable.  The price of simplicity.
+---------------

No, it's more of the same failure to type-check, combined with the
auto-reduce property of "subr_2n"s. If you look at that piece of code
I quoted before, you'll notice that the C code for the "plus" primitive
has a *fixed* arity of 2, but is initialized as a "subr_2n", which
causes the evaluator to do an implicit "reduce" on its arglist, calling
it with two args at a time, supplying the empty list for missing args.
That is, given (+), "eval" will call "plus(nil,nil)"; and given "(+ 1 2 3)",
eval will call "plus(plus(flonum(1), flonum(2)), flonum(3))".

The problem is, given *either* "(+ '() '() '())" or "(+ (+))", eval will
call "plus(plus(nil, nil), nil)", which reduces to "plus(0, nil)" which
reduces to "0" -- which is correct for the second form, but not the first.

That this is the case can be seen with the following amusing(?) assymetric
behavior when you permute these arguments:

	> (+ 1 2 '())		; same as (+ (+ 1 2)), so works fine.
	3
	> (+ 1 '() 2)		; same as (+ (+ 1) 2), so works fine.
	3
	> (+ '() 1 2)		; same as (+ (+ '() 1) 2), will fail.
	ERROR: wta(1st) to plus
	> (+ '() 1)             ; same as....\__this_/
	ERROR: wta(1st) to plus
	> 


-Rob

-----
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