Subject: Re: Barriers to Lisp acceptance - a "survey" question
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 1999/03/01
Newsgroups: comp.lang.lisp
Message-ID: <7bdtge$9nc9t@fido.engr.sgi.com>
Dorai Sitaram <ds26@bunny.gte.com> wrote:
+---------------
| Rob Warnock <rpw3@rigden.engr.sgi.com> wrote:
| >Most Schemes I've used have "fluid-let" or equivalent, which gets you
| >*that* style of dynamic usage of globals.  
| 
| Indeed.  However, I've always thought that a Scheme-like fluid-let may be
| more problematic for Scheme than it would be for Common Lisp, because it
| frustrates our take-it-for-granted expectation of tail-call optimization.
| (Common Lisp doesn't hold out this expectation, and so doesn't have the
| problem of having to cater to it.)
| Example:  [deleted]
+---------------

Yes, uh, well, umm... "It hurts when I do this."  "Well, don't..."  ;-}

Seriously, though, the "fluid-let" style [or anything similar, based on
dynamic-wind, say] *implies* a non-tail call, yes?  'Cause you want the
value to be set *back*, yes? So failing to preserve tail-call optimization
shouldn't come as a surprise.

If you want to mix "dynamic variables" with tail calls, I suggest that
the other style I mentioned, "parameters", might work better:

	(define *x* (make-parameter 0))  ; built into MzScheme but can be
					 ; written with closures
	(let loop ()
	  (*x* (+ (*x*) 1))
	  (display (*x*))
	  (newline)
	  (loop))

On MzScheme this version ran for over 100K loops (when I got tired watching)
with no evidence of increased memory usage, while the fluid-let version
started paging noticably at ~15K and crashed at ~40K:

	...
	40036
	40037
	40038
	40039
	Out of Memory!  Returning NIL!
	Segmentation fault (core dumped)
	% 


-Rob

p.s. I suspect I wouldn't use the CL "*foo*" naming style for "parameter"
closures, since invoking them (*foo*) looks too much like a Pascal comment!
On the other hand, just a leading "*" makes it look somewhat like a C function
pointer, (*foo (1+ (*foo))).  [Hmmm... A good thing or a bad thing? ;-} ]

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