Making evaluators with user-defined procedures

96 views Asked by At

So I'm working with DrRacket and since I'm making a manual via #lang scribble for my procedures I'd like to put actual examples of my procedures running using @interactions So far I've got this part:

#lang scribble/manual
@(require (for-label racket))
@(require scribble/eval racket/sandbox)
@(define my-evaluator
   (parameterize ([sandbox-output 'string]
                  [sandbox-error-output 'string])
     (make-evaluator 'racket/base '(define (f) later) '(define later 5))))

And when I do

@interaction[#:eval my-evaluator]{
                                  @(f)
                                   }

and then I run scribble --htmls ++main-xref-in manual.scrbl it correctly renders as:

> (f)
5

Is there a way to use all my definitios (that are in a different file) to evaluate using scribble? I've tried changing the line 7 for :

(make-evaluator 'racket/base '(define (f) later) '(define later 5) #:require "mydefs.rkt")))

But when I try to render it, it throws something like this:

make-evaluator: bad requires: "mydefs.rkt"

I don't want to copy paste my definitions in the make-evaluator part (they're a lot!) any fix? Thank you racketeers!

1

There are 1 answers

0
David Merinos On

asumu from IRC #racket helped me with this. All I needed was to do this:

@(define my-evaluator
   (parameterize ([sandbox-output 'string]
                  [sandbox-error-output 'string])
     (make-base-eval #:lang 'racket '(define (f) later) 
                     '(define later 5) 
                     '(require "../man/manager.rkt"))))

Note that instead of using keywords I just quoted the require statement.

Using

@interaction[#:eval my-evaluator]{
                                  @(define man (new manager%))@(send man crear-nodo '9)
                                   }

Renders perfectly.

Thanks!