Path: utzoo!utgpu!water!watmath!clyde!ima!think!barmar
From: barmar@think.COM (Barry Margolin)
Newsgroups: comp.lang.lisp
Subject: Re: nested function definitions
Message-ID: <22683@think.UUCP>
Date: 29 Jun 88 01:07:37 GMT
References: <5862@spool.cs.wisc.edu> <5568@utah-cs.UUCP> <3257@ubc-cs.UUCP> <22427@think.UUCP> <3266@ubc-cs.UUCP>
Sender: usenet@think.UUCP
Reply-To: barmar@kulla.think.com.UUCP (Barry Margolin)
Organization: Thinking Machines Corporation, Cambridge, MA
Lines: 47

In article <3266@ubc-cs.UUCP> manis@faculty.cs.ubc.ca (Vincent Manis) writes:
>Barry Margolin asks why I think DEFUN should be local if SETQ can be
>global. Basically, DEFUN performs an act of *binding*, whereas SETQ
>does an *assignment*.  A function or value cell need not exist prior
>to DEFUN (or any other DEF form), whereas such a cell must exist prior
>to SETQ.

Since when?  I can do (SETQ *FOO* 3) anyplace where (DEFUN FOO ...) is
permitted.  While it may be bad style to do this without first doing
(DEFVAR *FOO*), I don't think it is invalid.

>Because of this difference, I see DEFUN as a lot closer to LET than it
>is to SETQ. Since LET is lexically scoped, so too should DEFUN.

There is absolutely no precedent for this.  All the special forms that
instantiate a lexically-scoped name do so only within the body of that
special form.  You are proposing that in

(let (...)
  (defun foo ...)
  ...)

the scope of FOO would be the entire LET body, i.e. that the DEFUN
would affect the environment of the special form that contains it.
What about

(defun foo () (print 'outer))

(let ((bar nil))
  (setq bar #'(lambda () (foo)))
  (funcall bar)
  (defun foo () (print 'inner))
  (funcall bar))

Does this print OUTER followed by INNER, INNER twice, or does it get
an error?  I can think of justifications for all of these behaviors.

FLET and LABELS already exist for defining functions that can only be
accessed within a lexical scope.  What additional function does your
lexical DEFUN provide?


Barry Margolin
Thinking Machines Corp.

barmar@think.com
{uunet,harvard}!think!barmar