[Openmcl-devel] process-run-function and "dynamic vs lexical"
taoufik.dachraoui at wanadoo.fr
Thu Oct 22 11:42:12 EDT 2009
On Oct 22, 2009, at 4:42 PM, Tim Bradshaw wrote:
> On 22 Oct 2009, at 15:16, Taoufik Dachraoui wrote:
>> The last 2 tests are obviously what I expected but I do not
>> why when using process-run-function the y value within the new
>> is 1 and not 3. How to explain this, it is really confusing for me?
> I don't know CCL's threading model, but the standard thing would be
> that special bindings are per-thread.
Please note that the following is not to flame any debate it is
just for sake of clarifying and correcting my understandings.
Just for completeness I include the example:
? (defvar y 1)
? (let ((x 2) (y 3))
(labels ((f () (format t "~%x=~A y=~A~%" x y)))
(ccl:process-run-function "test" #'f)))
#<PROCESS test(3) [Reset] #x8D43546>
(let ((x 1)
let creates new variable binding for the names x and y and these
bindings are lexical unless they are declared special.
If all the names are not declared special then the let block must
be equivalent to the same block where the names are substitued by
other fresh arbitrary names.
And the following is a consequence of the previous statements: If
there is no special declaration for a given name, that name should
not be linked in any way to names outside the let block.
If the above is correct, I consider that the behavior of
ccl:process-run-function as shown in the example is not correct.
Indeed, if within the let block I change the name of y to z the
result will be different and there is no reason for this difference
because y in the let block should be a new variable binding for the
name y defined in the let block. It happens that there is a dynamic
variable y defined in the top level but since there is no special
declaration for the name y within the let block they must be
considered different as long as there is no special declaration
for y within the let block.
Where is my mistake, please note here that I would like to reconcile
my understanding with what I see while running ccl code.
More information about the Openmcl-devel