<div dir="ltr">Do you need to do the same thing with file/convertible?<div><br></div><div>Robby</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Oct 3, 2013 at 1:09 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">Here's another attempt at a patch. Would someone mind code reviewing it?<br>
<br>
Ryan pointed me towards sandbox-namespace-specs and it seems to do the<br>
trick. I also added some tests and the docs seem to compile ok.<br>
<div class="HOEnZb"><div class="h5"><br>
On Wed, Oct 2, 2013 at 7:21 PM, Robby Findler<br>
<<a href="mailto:robby@eecs.northwestern.edu">robby@eecs.northwestern.edu</a>> wrote:<br>
> namespace-attach-module sets up shared state between two modules so that, in<br>
> this case, the racket/pretty in one namespace is the same as the<br>
> racket/pretty in the other.<br>
><br>
> Try putting a printf in the top-level of racket/pretty (and in various other<br>
> places in that code as it does what it does) and then doing the<br>
> dynamic-require with and without the attach.<br>
><br>
> Robby<br>
><br>
><br>
> On Wed, Oct 2, 2013 at 4:58 PM, Stephen Chang <<a href="mailto:stchang@ccs.neu.edu">stchang@ccs.neu.edu</a>> wrote:<br>
>><br>
>> 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>
>><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<br>
>> > 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>><br>
>> > wrote:<br>
>> >> No, the 'racket/pretty' module might be declared even if the symbol<br>
>> >> 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<br>
>> >> 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<br>
>> >>>> are,<br>
>> >>>> as<br>
>> >>>> well as a separate mapping from module names to modules (roughly).<br>
>> >>>> What<br>
>> >>>> you<br>
>> >>>> care about here is the second mapping, but you're checking the first<br>
>> >>>> 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<br>
>> >>>>>> with<br>
>> >>>>>> whether racket/pretty can be attached.<br>
>> >>>>><br>
>> >>>>><br>
>> >>>>> Can you explain this a little more because it's a little unintuitive<br>
>> >>>>> 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<br>
>> >>>>>> have<br>
>> >>>>>> pretty-printing turned on by default.<br>
>> >>>>>><br>
>> >>>>>> Another option would be to attach racket/pretty before requiring<br>
>> >>>>>> the<br>
>> >>>>>> initial<br>
>> >>>>>> language for the namespace.<br>
>> >>>>>><br>
>> >>>>>> Another option is use #:pretty-print? #f when attaching<br>
>> >>>>>> 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>
><br>
><br>
</div></div></blockquote></div><br></div>