[Openmcl-devel] DEFUN inside LET (was: Thread-local bindings)

Ron Garret ron at flownet.com
Sun Jun 16 15:29:09 PDT 2019

On Jun 16, 2019, at 2:52 PM, Robert Munyer <2420506348 at munyer.com> wrote:

> Ron Garret wrote:
>> (let ((lock (make-lock))
> [snip]
>>  (defun out (s &rest args)
>>    (with-lock-grabbed (lock)
> I'd like to hear everyone's opinion about this construct.
> My own opinion of it is still inchoate.  I use it in unpublished CCL-only
> programs, especially if I'm doing Hoare-style concurrent programming, but
> I add a "TO DO" comment saying "before publishing this or porting it to a
> different compiler, find out if it's really OK that these DEFUN forms are
> not top-level forms”.

The CL spec specifically allows this.

"Evaluating defun causes function-name to be a global name for the function specified by the lambda expression … processed *in the lexical environment in which defun was executed*.”  (Emphasis added.)


But you might need to wrap it in an EVAL-WHEN to make sure it does the Right Thing in other implementations.


More information about the Openmcl-devel mailing list