[racket] Question about syntax splicing and formatting of the resulting code body

From: Grant Rettke (grettke at acm.org)
Date: Sat Jan 12 00:13:40 EST 2013

Thanks Danny and Matthew, this is seems to work well, it is like include,
but for an interaction environment:

@(require racket/sandbox
          scribble/eval
          racket
          (for-syntax racket))

@(define-syntax (ieval stx)
   (define (get-file path)
     (define fis (open-input-file #:mode 'text path))
     (port-count-lines! fis)
     (define-values (start-line start-column start-position)
(port-next-location fis))
     (define datums (port->list (lambda (port) (read-syntax path port))
fis))
     (define-values (end-line end-column end-position) (port-next-location
fis))
     (close-input-port fis)
     (define contents (datum->syntax #f datums (list path start-line
start-column start-position
                                    (if (and (number? start-position)
                                             (number? end-position))
                                        (- end-position start-position)
                                        #f))))
     (cons path contents))
   (syntax-case stx ()
     [(_ evaluator path)
      (with-syntax ([(exp ...) (get-file (syntax->datum #'path))])
        (syntax
         (begin
           @interaction[#:eval
                        evaluator
                        exp ...])))]))

; Usage

@(define my-evaluator
   (parameterize ([sandbox-output 'string]
                  [sandbox-error-output 'string])
     (make-evaluator 'racket)))

@(ieval my-evaluator "/home/gcr/racket-external-eval/some.rkt")

On Thu, Jan 10, 2013 at 1:36 PM, Danny Yoo <dyoo at hashcollision.org> wrote:

> > 1. Although the code collects the contents of that file in a list, is
> > there a way to splice (for lack of a better term) the contents of that
> > list into the scribble doc? The reason is that the generated document
> > is not identical to the original code:
>
>
> Maybe with the splice form?  But my understanding was that Scribble
> treats lists of pre-content as pre-content.
>
>
>
> > 2. I would like to insert the path name as a comment before the
> > imported text file. Is it as symbol as consing a symbol version of the
> > comment onto the datum list read by the file? I will check.
>
> Unfortunately, I'm not sure about this yet.
>



-- 
Grant Rettke | ACM, AMA, COG, IEEE
grettke at acm.org | http://www.wisdomandwonder.com/
Wisdom begins in wonder.
((λ (x) (x x)) (λ (x) (x x)))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130111/3ef524f6/attachment-0001.html>

Posted on the users mailing list.