<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Thank you Ron, Rainer and Bill<div class=""><br class=""></div><div class="">I hadn’t thought about the pervasiveness of defvar !</div><div class="">Also, from CLtL2, sec 9.2: <span style="font-family: -webkit-standard;" class="">A </span><tt class="">special</tt><span style="font-family: -webkit-standard;" class=""> </span><span style="font-family: -webkit-standard;" class="">declaration does</span><span style="font-family: -webkit-standard;" class=""> </span><i style="font-family: -webkit-standard;" class="">not</i><span style="font-family: -webkit-standard;" class=""> </span><span style="font-family: -webkit-standard;" class="">affect bindings pervasively. Inner bindings of a variable implicitly shadow a</span><span style="font-family: -webkit-standard;" class=""> </span><tt class="">special</tt><span style="font-family: -webkit-standard;" class=""> </span><span style="font-family: -webkit-standard;" class="">declaration and must be explicitly re-declared to be special. (However, a</span><span style="font-family: -webkit-standard;" class=""> </span><tt class="">special</tt><span style="font-family: -webkit-standard;" class="">proclamation</span><span style="font-family: -webkit-standard;" class=""> </span><i style="font-family: -webkit-standard;" class="">does</i><span style="font-family: -webkit-standard;" class=""> pervasively affect bindings; this exception is made for reasons of convenience and compatibility with MacLisp.)</span></div><div class=""><dt class=""><br class=""></dt><dt class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class="">Let’s look at special variables.</div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class="">The following result is expected:</div><div style="font-family: -webkit-standard; margin: 0px; font-stretch: normal; line-height: normal;" class=""><br class=""></div><div style="font-family: -webkit-standard; margin: 0px; font-stretch: normal; line-height: normal;" class=""><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">? (process-run-function :process1 </span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">  #'(lambda ()</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">      (let ((foo 4))</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">        (declare (special foo)) ; NOTE</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">        (flet ((bar () (print foo) :return-me-from-bar))</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">          (bar)</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">          (process-run-function :process2 #'bar)</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">          :return-me-from-lambda))))</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class="">4 </div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">> Error: Unbound variable: FOO</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">> While executing: BAR, in process PROCESS2(3).</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><div style="font-family: Helvetica;" class="">The thread-local binding rule looks like:</div><div style="font-family: Helvetica;" class="">— Lambda lexically closes over code running in a newly generated thread:</div><div style="font-family: Helvetica;" class=""><span class="Apple-tab-span" style="white-space: pre;">  </span>— except when a free variable in the new thread was dynamically scoped in the parent thread.</div><div class=""><br class=""></div></span></div></div></dt><dt class="">And … timing is everything!</dt></div><div class=""><div class="">When one wraps the test expression in a function definition, then it works one way when the definition is compiled before defvar declared, and it works the other way when the definition is compiled after defvar.</div><div class=""><br class=""></div><div class="">Actually, I am amazed that the closed-over case works.</div><div class="">In the following form, process1 terminates before process2 calls bar; nevertheless the call to bar has access to the lexical environment of process1 — or maybe that isn’t a correct description.</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">(process-run-function :process1 </span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">  #'(lambda ()</span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">      (let ((foo 4))</span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">        (flet ((bar () (print foo) :return-me-from-bar))</span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">          (bar)</span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">          (process-run-function :process2 #'(lambda () </span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">                                              (sleep 10) </span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">                                              (bar)</span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">                                              :return-me-from-lambda))))))</span></font></div></div></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><div style="font-family: Helvetica; font-size: 14px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 14px;" class="">Martin</div><div class=""><div style="font-family: Helvetica; font-size: 14px;" class=""><br class=""></div></div></span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div></div><div class=""><div><blockquote type="cite" class=""><div class="">On Jun 14, 2019, at 12:18 PM, Ron Garret <<a href="mailto:ron@flownet.com" class="">ron@flownet.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=windows-1252" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">You might want to read this:<div class=""><br class=""></div><div class=""><a href="http://www.flownet.com/ron/specials.pdf" class="">http://www.flownet.com/ron/specials.pdf</a></div><div class=""><br class=""></div><div class="">and particularly the section called “the pervasiveness of defvar”.</div><div class=""><br class=""></div><div class="">Also: instead of running your code at the top level, try putting it inside a function and calling the function before and after the DEFVAR.  You will see the different results.  The thing that is surprising you is happening at compile time.</div><div class=""><br class=""></div><div class="">rg</div><div class=""><br class=""><div class=""><div class="">On Jun 14, 2019, at 9:14 AM, Rainer Joswig <<a href="mailto:joswig@lisp.de" class="">joswig@lisp.de</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite" class=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">If a variable is used in a function and there is no special declaration and there is no DEFVAR, then the binding is lexical.</div><div class=""><br class=""></div><div class="">DEFVAR declares a variable to be special.<div class=""><br class=""></div><div class="">Then ALL new code on all levels (all lets, lambda vars, ...) will use dynamic binding.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""><blockquote type="cite" class=""><div class="">Am 14.06.2019 um 16:16 schrieb martin <<a href="mailto:brooks.martin@sympatico.ca" class="">brooks.martin@sympatico.ca</a>>:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hello All<div class=""><br class=""></div><div class="">I am confused about the semantics of thread-local bindings when using process-run-function. </div><div class="">CCL version: <span style="font-family: Menlo; font-size: 11px;" class="">Clozure Common Lisp Version 1.12-dev (v1.12-dev.4-3-gdd5622e9) DarwinX8664</span></div><div class=""><br class=""></div><div class="">Suppose that the variable <span style="font-family: Menlo; font-size: 11px; background-color: rgb(255, 255, 255);" class="">foo</span> is not globally bound:</div><div class=""><br class=""></div><div class=""><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">? foo</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">> Error: Unbound variable: FOO</span></div></div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class=""><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">Consider the following form:</div></div></div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">(process-run-function :process1 </span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">  #'(lambda ()</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">      (let ((foo 2))</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">        (flet ((bar () (print foo) :return-me-from-foo))</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">          (bar)</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">          (process-run-function :process2 #'bar)</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">          :return-me-from-lambda))))</span></div></div><div class=""><br class=""></div><div class="">The result is to print 2 twice:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">2 </span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">2 </span></div></div><div class=""><br class=""></div><div class="">Neither keyword return value appears, nor should they — I put them in the code to disambiguate printing from the value returned by print.</div><div class=""><br class=""></div><div class="">Now bind <span style="font-family: Menlo; font-size: 11px; background-color: rgb(255, 255, 255);" class="">foo</span> at top level.</div><div class=""><br class=""></div><div class=""><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">? (defvar foo 3)</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">FOO</span></div></div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class="">Execute the form again, to get these to print results:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">2 </span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">3 </span></div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class="">My confusion: </span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class="">The second result (print 2 & 3) demonstrates my understanding of thread-local bindings.</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class="">The first result (print 2 & 2) seems wrong — why didn’t Lisp complain that </span><span style="font-family: Menlo; font-size: 11px; background-color: rgb(255, 255, 255);" class="">foo </span>was unbound in the call to <span style="font-family: Menlo; font-size: 11px; background-color: rgb(255, 255, 255);" class="">bar</span> within <span style="font-family: Menlo; font-size: 11px; background-color: rgb(255, 255, 255);" class="">:process2 </span>?</div></div></div></blockquote><div class=""><br class=""></div><div class="">Because FOO uses the lexical binding introduced by the LET.</div><br class=""><blockquote type="cite" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">My confusion gets worse — restart Lisp, so that <span style="font-family: Menlo; font-size: 11px; background-color: rgb(255, 255, 255);" class="">foo</span> is not globally bound, and do the same tests with the following form, to see it print 4 & 4.</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">(let ((foo 4))</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">  (process-run-function :process1 </span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">    #'(lambda ()</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">      </span>  (flet ((bar () (print foo) :return-me-from-foo))</div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">          (bar)</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">          (process-run-function :process2 #'bar)</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">          :return-me-from-lambda))))</span></div></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">4 </span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">4 </span></div></span></div><div class=""><br class=""></div></div></blockquote><div class=""><br class=""></div><div class=""><br class=""></div>lexical binding</div><div class=""><br class=""></div><div class=""><br class=""><blockquote type="cite" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">And now globally bind <span style="font-family: Menlo; font-size: 11px; background-color: rgb(255, 255, 255);" class="">foo</span>:</div><div class=""><br class=""></div><div class=""><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">? (defvar foo 5)</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">FOO</span></div></div></div></div></blockquote><div class=""><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div><div class="">The form now prints 5 & 5 .</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">5 </span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">5</span></div></div><div class=""><br class=""></div></div></div></blockquote><div class=""><br class=""></div><div class="">dynamic binding</div><div class=""><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">Help! What’s the rule?!?</div><div class=""><br class=""></div><div class=""><div class="">Furthermore, I take it that stack-local bindings apply to variables only, not functions.</div></div><div class="">To test this, I gave <span style="font-family: Menlo; font-size: 11px;" class="">bar</span> a global definition:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">(defun bar () (print 27))</span></div></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">But this did not change the above results; in other words, the local definition was used in both threads.</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">All consolation gratefully accepted,</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">Martin</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div></div>_______________________________________________<br class="">Openmcl-devel mailing list<br class=""><a href="mailto:Openmcl-devel@clozure.com" class="">Openmcl-devel@clozure.com</a><br class=""><a href="https://lists.clozure.com/mailman/listinfo/openmcl-devel" class="">https://lists.clozure.com/mailman/listinfo/openmcl-devel</a><br class=""></div></blockquote></div><br class=""></div></div>_______________________________________________<br class="">Openmcl-devel mailing list<br class=""><a href="mailto:Openmcl-devel@clozure.com" class="">Openmcl-devel@clozure.com</a><br class=""><a href="https://lists.clozure.com/mailman/listinfo/openmcl-devel" class="">https://lists.clozure.com/mailman/listinfo/openmcl-devel</a><br class=""></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></div></div></body></html>