I thought that when you compile with (declare (block)), the variable references created to exported-var of a.scm from b.scm would be bound to the first loaded version. This was however not the case.

This is how it is: any variable references you make in closures and data structures are locked to the first version. All other are not. Very nice!

Mikael


(work-closure1 below is indeed not a closure.)

mc@debian:/tmp$ cat > a.scm.1

(print "Module A import\n")
(define exported-var 'something)
mc@debian:/tmp$ cat > a.scm.2

(print "Module A import\n")
(define exported-var 'something-else)
mc@debian:/tmp$ cat > b.scm

(import a)

(define (work-when-separate) exported-var)
(begin (declare (block)) (define (work-when-block) exported-var))

(define work-closure1 (lambda () exported-var))
(define work-closure2 (let ((c exported-var)) (lambda () c)))

(define structure (cons exported-var 'something-tihrd))
debian:/tmp# bsc
> (import b)
Module A import
> (work-when-separate) (work-when-block) (work-closure1) (work-closure2) structure
something
> something
> something
> something
> (something . something-tihrd)
>
[1]+  Stopped                 bsc
debian:/tmp# cp a.scm.2 a.scm
debian:/tmp# fg
bsc
(import b)
Module A import
> (work-when-separate) (work-when-block) (work-closure1) (work-closure2) structure
something-else
> something-else
> something-else
> something
> (something . something-tihrd)
> ,q
debian:/tmp# bsc
> (module-compile! 'b)
>
[1]+  Stopped                 bsc
debian:/tmp# cp a.scm.1 a.scm
debian:/tmp# fg
bsc

(module-compile! 'a)
> (import b)
Module A import
> (work-when-separate) (work-when-block) (work-closure1) (work-closure2) structure
something
> something
> something
> something
> (something . something-tihrd)
>
[1]+  Stopped                 bsc
debian:/tmp# cp a.scm.2 a.scm
debian:/tmp# fg
bsc
(import b)
/tmp/a is being compiled...
Module A import
> (work-when-separate) (work-when-block) (work-closure1) (work-closure2) structure
something-else
> something-else
> something-else
> something
> (something . something-tihrd)

>


2009/7/15 Per Eckerdal <per.eckerdal@gmail.com>:
> Jag förstår inte frågan?
>
> 15 jul 2009 kl. 11.01 skrev Mikael More:
>
>> Per,
>>
>> Regarding what variable references that module B does to module A, that
>> are updated when A has been changed and you import A again (for instance
>> through importing B again) -
>>
>> given a.scm:
>>
>> (print "Module A import\n")
>> (define exported-var 'something)
>>
>> And b.scm:
>>
>> (import a)
>>
>> (define (work-when-separate) exported-var)
>> (begin (declare (block)) (define (work-when-block) exported-var))
>>
>> (define work-closure1 (lambda () exported-var))
>> (define work-closure2 (let ((c exported-var)) (lambda () c)))
>>
>> (define structure (cons exported-var 'something-tihrd))
>>
>> And doing (import b) in BH
>>
>> And then altering a.scm into:
>>
>> (print "Module A import\n")
>> (define exported-var 'something-else)
>>
>> And doing (import b) again, thus reimporting a:
>>
>> I get something-else from (work-when-separate), (work-when-block) and
>> (work-closure1), both when B is executed in interpreted and compiled mode.
>>
>> Even if it's great from incremental development point of view; should it
>> really be like this?
>>
>> Mikael
>>
>> _______________________________________________
>> Gambit-modules-list mailing list
>> Gambit-modules-list@mercure.iro.umontreal.ca
>> https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-modules-list
>
>