[racket] Scribbling HTDP

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Feb 27 11:12:24 EST 2012

The `make-evaluator' function just `require's the specified module into
the sandbox's namespace. It doesn't set up reading or printing.

The most important part of the code fragment below is

  ((dynamic-require 'htdp/bsl/runtime 'configure)
   (dynamic-require reader 'options))

which triggers the run-time configuration of the `htdp/*sl' languages,
which sets reading and printing parameters.

All of this is a step on the way to an improved `make-evaluator' that
is like using `#lang' or picking a language with `racket -I ...', but
no one has filled in the pieces, yet.


At Mon, 27 Feb 2012 09:59:47 -0600, Robby Findler wrote:
> Why is make-evaluator insufficient?
> 
> On Mon, Feb 27, 2012 at 9:55 AM, Matthias Felleisen
> <matthias at ccs.neu.edu> wrote:
> >
> > I was wrong. The code below accomplishes what you want. It sets up an 
> evaluator in the *sl languages, including hooks to print #t and #f properly.
> >
> > (Matthew reminded me but I had to re-run the rendering script in a clean 
> directory to validate his reminder.)
> >
> >
> >
> > (define-syntax-rule
> >  (*sl-eval module-lang reader def ...)
> >  ;; ===>>>
> >  (let ()
> >    (define me (make-base-eval))
> >    (me '(require (only-in racket empty? first rest cons? sqr true false)))
> >    (me '(require lang/posn))
> >    (me '(require racket/pretty))
> >    (me '(current-print pretty-print-handler))
> >    (me '(pretty-print-columns 65))
> >    (me 'def)
> >    ...
> >    (call-in-sandbox-context me (lambda () (error-print-source-location #f)))
> >    (call-in-sandbox-context me (lambda ()
> >                                  (current-print-convert-hook
> >                                    (let ([prev (current-print-convert-hook)])
> >                                      ;; tell `print-convert' to leave images 
> as themselves:
> >                                      (lambda (v basic sub)
> >                                        (if (convertible? v)
> >                                            v
> >                                            (prev v basic sub)))))
> >
> >                                  (pretty-print-size-hook
> >                                    (let ([prev (pretty-print-size-hook)])
> >                                      ;; tell `pretty-print' that we'll handle 
> images specially:
> >                                      (lambda (v w? op)
> >                                        (if (convertible? v) 1 (prev v w? 
> op)))))
> >
> >                                  (pretty-print-print-hook
> >                                    (let ([prev (pretty-print-print-hook)])
> >                                      ;; tell `pretty-print' how to handle 
> images, which is
> >                                      ;; by using `write-special':
> >                                      (lambda (v w? op)
> >                                        (if (convertible? v) (write-special v 
> op) (prev v w? op)))))
> >
> >                                  ((dynamic-require 'htdp/bsl/runtime 
> 'configure)
> >                                   (dynamic-require reader 'options))))
> >    (call-in-sandbox-context me (lambda () (namespace-require module-lang)))
> >    (interaction-eval #:eval me (require 2htdp/image))
> >    (interaction-eval #:eval me (require 2htdp/batch-io))
> >    ;; --- splice in the defs
> >    me))
> >
> > (define-syntax-rule
> >  (bsl-eval def ...)
> >  (*sl-eval 'lang/htdp-beginner 'htdp/bsl/lang/reader def ...))
> >
> > (define-syntax-rule
> >  (bsl-eval+ def ...)
> >  (*sl-eval 'lang/htdp-beginner-abbr 'htdp/bsl+/lang/reader def ...))
> >
> > (define-syntax-rule
> >  (isl-eval def ...)
> >  (*sl-eval 'lang/htdp-intermediate 'htdp/isl/lang/reader def ...))
> >
> > (define-syntax-rule
> >  (isl-eval+ def ...)
> >  (*sl-eval 'lang/htdp-intermediate-lambda 'htdp/isl/lang/reader def ...))
> >
> >
> >
> >
> >
> > On Feb 27, 2012, at 10:31 AM, Robby Findler wrote:
> >
> >> Should consider this a bug (that that the call to make-evaluator below
> >> doesn't set things up properly for this usecase)?
> >>
> >> Robby
> >>
> >> On Mon, Feb 27, 2012 at 9:27 AM, Matthias Felleisen
> >> <matthias at ccs.neu.edu> wrote:
> >>>
> >>> I am running a short filter function on the output that changes #t to true. 
> -- Matthias
> >>>
> >>>
> >>>
> >>> On Feb 27, 2012, at 10:23 AM, Klaus Ostermann wrote:
> >>>
> >>>> Hi all,
> >>>>
> >>>> I want to use Scribble for some lecture notes using HTDP/2e.
> >>>>
> >>>> The example "An Introduction to Racket with Pictures" illustrates how to 
> use Scribble and embed Racket evaluation. However, the HTDP
> >>>> languages behave different in some ways - for instance, they
> >>>> print "#t" as "true" and various other differences.
> >>>>
> >>>> How can I use Scribble to write about examples in the HTDP languages?
> >>>> I want the exact behavior of the HTDP languages. Using, say,
> >>>> (make-evaluator 'lang/htdp-intermediate)
> >>>> is not sufficient.
> >>>>
> >>>> HTDP/2e itself seems to be written using Scribble, which would mean that 
> there is already a solution to this problem (?).
> >>>>
> >>>> Regards,
> >>>> Klaus
> >>>> ____________________
> >>>> 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
> 
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users


Posted on the users mailing list.