Here is another patch, with Ryan's suggestion.

If no one has any objections, I will push tomorrow.

On Mon, Mar 3, 2014 at 10:01 PM, Sam Tobin-Hochstadt
<sa...@cs.indiana.edu> wrote:
> What was unsatisfactory about your last patch, aside from Ryan's suggestion?
>
> Sam
>
> On Mar 3, 2014 8:46 PM, "Stephen Chang" <stch...@ccs.neu.edu> wrote:
>>
>> I filed this bug a few months ago:
>>
>> http://bugs.racket-lang.org/query/?cmd=view%20audit-trail&database=default&pr=14066&return_url=http%3A%2F%2Fbugs.racket-lang.org%2Fquery%2F%3FResponsible%3Dstchang%3BState%3Dopen%3Bcolumns%3DCategory%3Bcolumns%3DSeverity%3Bcolumns%3DOriginator%3Bcolumns%3DSynopsis%3Bcmd%3Dsubmit%2520query%3Bsortby%3DNumber
>>
>> I worked on a fix but was unable to come up with a satisfactory fix.
>> Here is the discussion:
>> http://lists.racket-lang.org/dev/archive/2013-October/013454.html
>>
>>
>>
>> On Mon, Mar 3, 2014 at 8:32 PM, Greg Hendershott
>> <greghendersh...@gmail.com> wrote:
>> > Or this:
>> >
>> > #lang scribble/manual
>> > @(require scribble/eval)
>> > @(define some-eval
>> >    (make-base-eval))
>> > @(require racket)
>> >
>> > On Mon, Mar 3, 2014 at 8:29 PM, Greg Hendershott
>> > <greghendersh...@gmail.com> wrote:
>> >> I get the same error with your code. It looks like there's a
>> >> #:pretty-print arg that defaults to #t. If I set it #f it works for
>> >> me:
>> >>
>> >> #lang scribble/manual
>> >> @(require scribble/eval)
>> >> @(define some-eval
>> >>    (make-base-eval #:lang 'racket
>> >>                    #:pretty-print? #f))
>> >>
>> >>
>> >> On Mon, Mar 3, 2014 at 8:09 PM, David Van Horn <dvanh...@cs.umd.edu>
>> >> wrote:
>> >>> I was just dusting off old notes I have written in scribble that used
>> >>> to
>> >>> work, but now I get an error, which I've boiled down to the following
>> >>> example:
>> >>>
>> >>> $ cat try.scrbl
>> >>> #lang scribble/manual
>> >>> @(require scribble/eval)
>> >>> @(define some-eval
>> >>>    (make-base-eval #:lang 'racket))
>> >>>
>> >>> $ scribble --pdf try.scrbl
>> >>> namespace-attach-module: a different module with the same name is
>> >>> already in the destination namespace
>> >>>   module name:
>> >>> "/Users/dvanhorn/git/racket/racket/collects/racket/pretty.rkt"
>> >>>   context...:
>> >>>
>> >>>
>> >>> /Users/dvanhorn/git/racket/pkgs/scribble-pkgs/scribble-lib/scribble/eval.rkt:342:4
>> >>>
>> >>>
>> >>> /Users/dvanhorn/git/racket/racket/collects/racket/private/more-scheme.rkt:147:2:
>> >>> call-with-break-parameterization
>> >>>
>> >>> /Users/dvanhorn/git/racket/pkgs/sandbox-lib/racket/sandbox.rkt:833:5:
>> >>> loop
>> >>>
>> >>> This is on 6.0.0.2--2014-02-04.
>> >>>
>> >>> Is this something that should work, or have I done something wrong.
>> >>> Is
>> >>> there some way for me to work around the pretty.rkt issue?
>> >>>
>> >>> Thanks,
>> >>> David
>> >>> ____________________
>> >>>   Racket Users list:
>> >>>   http://lists.racket-lang.org/users
>> > ____________________
>> >   Racket Users list:
>> >   http://lists.racket-lang.org/users
>>
>> ____________________
>>   Racket Users list:
>>   http://lists.racket-lang.org/users
From 0eac6b96ab56bbf9851d6c3b72dd672fc96768aa Mon Sep 17 00:00:00 2001
From: Stephen Chang <stch...@ccs.neu.edu>
Date: Tue, 4 Mar 2014 16:25:54 -0500
Subject: [PATCH 1/2] fix scribble make-base-eval racket/pretty namespace
 error

closes pr 14066
---
 pkgs/scribble-pkgs/scribble-lib/scribble/eval.rkt |   41 ++++++++++-----------
 1 file changed, 19 insertions(+), 22 deletions(-)

diff --git a/pkgs/scribble-pkgs/scribble-lib/scribble/eval.rkt b/pkgs/scribble-pkgs/scribble-lib/scribble/eval.rkt
index 7cc491c..5031d53 100644
--- a/pkgs/scribble-pkgs/scribble-lib/scribble/eval.rkt
+++ b/pkgs/scribble-pkgs/scribble-lib/scribble/eval.rkt
@@ -337,30 +337,29 @@
     [(eq? stx 'code:blank) (void)]
     [else stx]))
 
-(define (install-pretty-printer! e ns)
-  (call-in-sandbox-context e
-    (lambda ()
-      (namespace-attach-module ns 'racket/pretty)
-      (current-print (dynamic-require 'racket/pretty 'pretty-print-handler)))))
-
 (define (make-base-eval #:lang [lang '(begin)] #:pretty-print? [pretty-print? #t] . ips)
   (call-with-trusted-sandbox-configuration
    (lambda ()
      (parameterize ([sandbox-output 'string]
                     [sandbox-error-output 'string]
-                    [sandbox-propagate-breaks #f])
+                    [sandbox-propagate-breaks #f]
+                    [sandbox-namespace-specs
+                     (append (sandbox-namespace-specs)
+                             (if pretty-print?
+                                 '(racket/pretty file/convertible)
+                                 '(file/convertible)))])
        (let ([e (apply make-evaluator lang ips)])
-         (let ([ns (namespace-anchor->namespace anchor)])
-           (call-in-sandbox-context
-            e
-            (lambda () (namespace-attach-module ns 'file/convertible)))
-           (when pretty-print? (install-pretty-printer! e ns)))
+         (when pretty-print?
+           (call-in-sandbox-context e
+             (lambda ()
+               (current-print (dynamic-require 'racket/pretty 'pretty-print-handler)))))
          e)))))
 
 (define (make-base-eval-factory mod-paths
                                 #:lang [lang '(begin)]
                                 #:pretty-print? [pretty-print? #t] . ips)
-  (let ([ns (delay (let ([ns 
+  (parameterize ([sandbox-namespace-specs
+                  (cons (λ () (let ([ns
                           ;; This namespace-creation choice needs to be consistent
                           ;; with the sandbox (i.e., with `make-base-eval')
                           (if gui?
@@ -370,16 +369,14 @@
                        (for ([mod-path (in-list mod-paths)])
                          (dynamic-require mod-path #f))
                        (when pretty-print? (dynamic-require 'racket/pretty #f)))
-                     ns))])
+                                ns))
+                        (append mod-paths (if pretty-print? '(racket/pretty) '())))])
     (lambda ()
-      (let ([ev (apply make-base-eval #:lang lang #:pretty-print? #f ips)]
-            [ns (force ns)])
-        (when pretty-print? (install-pretty-printer! ev ns))
-        (call-in-sandbox-context
-         ev
-         (lambda ()
-           (for ([mod-path (in-list mod-paths)])
-             (namespace-attach-module ns mod-path))))
+      (let ([ev (apply make-base-eval #:lang lang #:pretty-print? #f ips)])
+        (when pretty-print?
+          (call-in-sandbox-context ev
+            (lambda ()
+              (current-print (dynamic-require 'racket/pretty 'pretty-print-handler)))))
         ev))))
 
 (define (make-eval-factory mod-paths
-- 
1.7.9.5


From 77c2187c2fbccaf6a19f350a5ecca001b69fcfc8 Mon Sep 17 00:00:00 2001
From: Stephen Chang <stch...@ccs.neu.edu>
Date: Tue, 4 Mar 2014 16:27:32 -0500
Subject: [PATCH 2/2] add tests for scribble/eval

---
 .../scribble-test/tests/scribble/eval.rkt          |   71 ++++++++++++++++++++
 1 file changed, 71 insertions(+)
 create mode 100644 pkgs/scribble-pkgs/scribble-test/tests/scribble/eval.rkt

diff --git a/pkgs/scribble-pkgs/scribble-test/tests/scribble/eval.rkt b/pkgs/scribble-pkgs/scribble-test/tests/scribble/eval.rkt
new file mode 100644
index 0000000..e303ad9
--- /dev/null
+++ b/pkgs/scribble-pkgs/scribble-test/tests/scribble/eval.rkt
@@ -0,0 +1,71 @@
+#lang racket/base
+(require scribble/eval scribble/core rackunit racket/match)
+
+(check-not-exn (λ () (make-base-eval)))
+(check-not-exn (λ () (make-base-eval #:pretty-print? #t #:lang 'racket/base)))
+(check-not-exn (λ () (make-base-eval #:pretty-print? #t #:lang 'racket)))
+(check-not-exn (λ () (make-base-eval #:pretty-print? #t #:lang 'typed/racket)))
+(check-not-exn (λ () (make-base-eval #:pretty-print? #t #:lang 'lazy)))
+(check-not-exn (λ () (make-base-eval #:pretty-print? #f #:lang 'racket/base)))
+(check-not-exn (λ () (make-base-eval #:pretty-print? #f #:lang 'racket)))
+(check-not-exn (λ () (make-base-eval #:pretty-print? #f #:lang 'typed/racket)))
+(check-not-exn (λ () (make-base-eval #:pretty-print? #f #:lang 'lazy)))
+
+(check-not-exn (λ () ((make-base-eval-factory '() #:pretty-print? #t))))
+(check-not-exn (λ () ((make-base-eval-factory '() #:pretty-print? #t #:lang 'racket/base))))
+(check-not-exn (λ () ((make-base-eval-factory '() #:pretty-print? #t #:lang 'racket))))
+(check-not-exn (λ () ((make-base-eval-factory '() #:pretty-print? #t #:lang 'typed/racket))))
+(check-not-exn (λ () ((make-base-eval-factory '() #:pretty-print? #t #:lang 'lazy))))
+
+(check-not-exn (λ () ((make-eval-factory '() #:pretty-print? #t))))
+(check-not-exn (λ () ((make-eval-factory '() #:pretty-print? #t #:lang 'racket/base))))
+(check-not-exn (λ () ((make-eval-factory '() #:pretty-print? #t #:lang 'racket))))
+(check-not-exn (λ () ((make-eval-factory '() #:pretty-print? #t #:lang 'typed/racket))))
+(check-not-exn (λ () ((make-eval-factory '() #:pretty-print? #t #:lang 'lazy))))
+
+(define (get-result-blocks nf)
+  (match (nested-flow-blocks nf) [(list (table _ (list _ res))) res]))
+
+(define filter-datum '(define (filter p? lst) 
+                        (if (null? lst) 
+                            null 
+                            (let ([x (car lst)]) 
+                              (if (p? x)
+                                  (cons x (filter p? (cdr lst)))
+                                  (filte p? (cdr lst)))))))
+;; check that pretty printing is working
+(define pp-blocks
+  (car
+   (get-result-blocks
+    (interaction #:eval (make-base-eval #:pretty-print? #t #:lang 'racket)
+                 '(define (filter p? lst) 
+                    (if (null? lst) 
+                        null 
+                        (let ([x (car lst)])
+                          (if (p? x) 
+                              (cons x (filter p? (cdr lst)))
+                              (filter p? (cdr lst))))))))))
+(check-true (table? pp-blocks)) ; multiple line result gets put in a table of paragraphs
+(check-equal? (length (table-blockss pp-blocks)) 5) ;; pretty printed into 5 lines
+
+(define non-pp-blocks
+  (car
+   (get-result-blocks
+    (interaction #:eval (make-base-eval #:pretty-print? #f #:lang 'racket) 
+                 '(define (filter p? lst)
+                    (if (null? lst) 
+                        null 
+                        (let ([x (car lst)]) 
+                          (if (p? x) 
+                              (cons x (filter p? (cdr lst)))
+                              (filter p? (cdr lst))))))))))
+(check-true (paragraph? non-pp-blocks)) ;; single line result is just 1 paragraph
+
+;; check that different evaluators do not share a single namespace
+(define e1 (make-base-eval))
+(define e2 (make-base-eval))
+(check-exn exn:fail:contract:variable? (λ () (e1 '(current-date))))
+(check-exn exn:fail:contract:variable? (λ () (e2 '(current-date))))
+(e1 '(require racket/date))
+(check-not-exn (λ () (e1 '(current-date))))
+(check-exn exn:fail:contract:variable? (λ () (e2 '(current-date))))
-- 
1.7.9.5

____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Reply via email to