[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Scheme-reports] loading libraries



When I first implemented support for libraries I thought that it was 
required that each time a library was imported it had to be loaded which 
seemed weird; obviously, I had not read the specification closely 
enough. When I realized why parameters were not working, I went back and 
read the specification much more closely, and then fixed my library 
support to load libraries only once.

Why is the specification vague about how many times libraries get 
loaded? As a user of scheme, it would be much clearer to me to be able 
to look at a library and know that it was going to be loaded exactly once.

On 10/24/2013 6:28 AM, Sam Tobin-Hochstadt wrote:
> No implementation, to my knowledge, has ever loaded libraries multiple
> times in the example you gave.  Racket loads modules separately for
> each modules's compilation, because each compilation of a single
> module has its own store, not shared with runtime or any other
> compilation.
>
> This modification of your program shows an aspect of Racket's behavior
> -- it writes `(small cake)`.
>
> #lang racket/load
>
> (module |(bakery size)| racket
>    (provide size)
>    (define size (make-parameter 'small)))
>
> (module |(bakery cake)| racket
>    (require (for-syntax '|(bakery size)|))
>    (provide make-cake)
>    (begin
>      (define-syntax (make-cake stx)
>        #`(quote
>           #,(list (size) 'cake)))))
>
> ;; program
> (require '|(bakery size)|)
> (require '|(bakery cake)|)
>
> (parameterize ((size 'large)) (write (make-cake)))
>
>
> On Thu, Oct 24, 2013 at 12:33 AM, Michael Montague <mikemon@x> wrote:
>> On 10/23/2013 6:12 PM, Alex Shinn wrote:
>>> The libraries may in fact be loaded multiple times,
>>> to allow for models such as Racket which require
>>> clean environments for each library expansion in
>>> order to avoid unwanted macro interactions.
>>>
>> I don't understand how parameters work in implementations where
>> libraries can be loaded more than once.
>>
>> In the following example, each time (bakery size) is loaded, size will
>> be bound to a different parameter. An implementation that loads
>> libraries each time they are imported would write (small cake). And an
>> implementation which loads libraries only once would write (large cake).
>>
>> (define-library (bakery size)
>>       (import (scheme base))
>>       (export size)
>>       (begin
>>           (define size (make-parameter 'small))))
>>
>> (define-library (bakery cake)
>>       (import (scheme base))
>>       (import (bakery size))
>>       (export make-cake)
>>       (begin
>>           (define (make-cake)
>>               (list (size) 'cake))))
>>
>> ;; program
>> (import (scheme base))
>> (import (scheme write))
>> (import (bakery size))
>> (import (bakery cake))
>>
>> (parameterize ((size 'large)) (write (make-cake)))
>>
>>
>>
>>
>>
>> _______________________________________________
>> Scheme-reports mailing list
>> Scheme-reports@x
>> http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports


_______________________________________________
Scheme-reports mailing list
Scheme-reports@x
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports