<div dir="ltr">namespace-attach-module sets up shared state between two modules so that, in this case, the racket/pretty in one namespace is the same as the racket/pretty in the other.<div><br></div><div>Try putting a printf in the top-level of racket/pretty (and in various other places in that code as it does what it does) and then doing the dynamic-require with and without the attach.</div>
<div><br></div><div>Robby</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Oct 2, 2013 at 4:58 PM, Stephen Chang <span dir="ltr"><<a href="mailto:stchang@ccs.neu.edu" target="_blank">stchang@ccs.neu.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Ok here's another dumb question. Why is that namespace-attach-module<br>
even needed? It seems the dynamic require on the next line does the<br>
desired thing?<br>
<div class="HOEnZb"><div class="h5"><br>
On Wed, Oct 2, 2013 at 4:16 PM, Stephen Chang <<a href="mailto:stchang@ccs.neu.edu">stchang@ccs.neu.edu</a>> wrote:<br>
> Ok thanks for the explanations. I'll try doing one of the last two suggestions.<br>
><br>
> On Wed, Oct 2, 2013 at 4:09 PM, Ryan Culpepper <<a href="mailto:ryanc@ccs.neu.edu">ryanc@ccs.neu.edu</a>> wrote:<br>
>> No, the 'racket/pretty' module might be declared even if the symbol isn't<br>
>> defined (or "mapped") in the namespace:<br>
>><br>
>>   > (define ns (make-base-namespace))<br>
>>   > (define repl-ns (current-namespace))<br>
>>   > (parameterize ((current-namespace ns))<br>
>>       (eval '(require (only-in racket/pretty))))<br>
>>   > (parameterize ((current-namespace ns))<br>
>>       (namespace-attach-module repl-ns 'racket/pretty))<br>
>>   namespace-attach-module: a different module with the same name is<br>
>>   already in the destination namespace<br>
>>     module name: "/opt/racket-5.3.6/collects/racket/pretty.rkt"<br>
>>     context...:<br>
>>      /opt/racket-5.3.6/collects/racket/private/misc.rkt:87:7<br>
>><br>
>> And the symbol can be defined in the namespace even if the module is not<br>
>> declared:<br>
>><br>
>>   > (define ns (make-base-namespace))<br>
>>   > (define repl-ns (current-namespace))<br>
>>   > (parameterize ((current-namespace ns))<br>
>>       (eval '(define pretty-print-handler #t)))<br>
>>   > (parameterize ((current-namespace ns))<br>
>>       (namespace-variable-value 'pretty-print-handler))<br>
>>   #t<br>
>>   ;; but racket/pretty is not declared,<br>
>>   ;; and #t is not a good print handler<br>
>><br>
>> Ryan<br>
>><br>
>><br>
>><br>
>> On 10/02/2013 03:58 PM, Stephen Chang wrote:<br>
>>>><br>
>>>> A namespace is a mapping from top-level identifiers to whatever they are,<br>
>>>> as<br>
>>>> well as a separate mapping from module names to modules (roughly). What<br>
>>>> you<br>
>>>> care about here is the second mapping, but you're checking the first with<br>
>>>> the patch.<br>
>>><br>
>>><br>
>>> Thanks for the explanation. That helps a lot. So the danger with my<br>
>>> check is when someone has another definition of pretty-print handler<br>
>>> but racket/pretty has not been attached?<br>
>>><br>
>>> But given the context, ie the dynamic require on the next line, it<br>
>>> seems like there's already an assumption about what the identifier I'm<br>
>>> checking is, so in this specific situation, isnt my check sufficient?<br>
>>><br>
>>><br>
>>><br>
>>>><br>
>>>> Robby<br>
>>>><br>
>>>><br>
>>>> On Wed, Oct 2, 2013 at 2:45 PM, Stephen Chang <<a href="mailto:stchang@ccs.neu.edu">stchang@ccs.neu.edu</a>><br>
>>>> wrote:<br>
>>>>><br>
>>>>><br>
>>>>>> Whether that identifier exists in the namespace has nothing to do with<br>
>>>>>> whether racket/pretty can be attached.<br>
>>>>><br>
>>>>><br>
>>>>> Can you explain this a little more because it's a little unintuitive to<br>
>>>>> me?<br>
>>>>><br>
>>>>><br>
>>>>>><br>
>>>>>> One option would be for install-pretty-printer! to just catch and<br>
>>>>>> discard<br>
>>>>>> the error. Evaluators for some languages would mysteriously not have<br>
>>>>>> pretty-printing turned on by default.<br>
>>>>>><br>
>>>>>> Another option would be to attach racket/pretty before requiring the<br>
>>>>>> initial<br>
>>>>>> language for the namespace.<br>
>>>>>><br>
>>>>>> Another option is use #:pretty-print? #f when attaching racket/pretty<br>
>>>>>> would<br>
>>>>>> fail.<br>
>>>>>><br>
>>>>>> Ryan<br>
>>>>>><br>
>>>>> _________________________<br>
>>>>>    Racket Developers list:<br>
>>>>>    <a href="http://lists.racket-lang.org/dev" target="_blank">http://lists.racket-lang.org/dev</a><br>
>>>><br>
>>>><br>
>>>><br>
>><br>
</div></div></blockquote></div><br></div>