21 drracket:eval

▼ |  | Dr Racket Plugins

1 | Dr Racket support for #lang-based Languages
2 | Implementing Dr Racket Plugins
3 | Adding Languages to Dr Racket
4 | Creating New Kinds of Dr Racket Frames
5 | Extending the Existing Dr Racket Classes
6 | Expanding the User’s Program Text and Breaking
7 | Editor Modes
8 | Plugin Capabilities
9 | Check Syntax
10 | Cooperating with Background Check Syntax
11 | Teaching Languages
12 | Signatures
13 | drracket: get/ extend
14 | drracket: unit
15 | drracket: language
16 | drracket: language-configuration
17 | drracket: debug
18 | drracket: rep
19 | drracket: frame
20 | drracket: help-desk
21 | drracket: eval
22 | drracket: modes
23 | drracket: module-language-tools
24 | drracket: module-language
25 | drracket: tracing
26 | Backwards Compatibility
| Index

On this page:

drracket: eval: set-basic-parameters
drracket: eval: get-snip-classes
drracket: eval: expand-program
drracket: eval: traverse-program/ multiple
drracket: eval: expand-program/ multiple
drracket: eval: build-user-eventspace/ custodian

top ← prev up next →

### 21`` drracket:eval

> > procedure
> > (drracket:eval:set-basic-parameters |
> > |  | snipclasses |
> > | [ | #:gui-modules? gui-modules]) |
> → void?
> snipclasses : (listof (is-a?/c snip-class%))
> gui-modules : boolean? = #t

Sets the parameters that are shared between the repl’s initialization and drracket:eval:build-user-eventspace/custodian.

Specifically, it sets these parameters:

- current-namespace has been set to a newly created empty namespace. This namespace has the following modules shared (with namespace-attach-module) from DrRacket’s original namespace:

  - racket/base

  - '#%foreign

  - mzlib/pconvert-prop

  - planet/terse-info

  If the gui-modules? parameter is a true value, then these modules are also shared:

  - mred/mred

  - mrlib/cache-image-snip

  - mrlib/image-core

  - mrlib/matrix-snip

- read-curly-brace-as-paren is #t;

- read-square-bracket-as-paren is #t;

- error-print-width is set to 250;

- current-ps-setup is set to a newly created ps-setup% object;

- the exit-handler is set to a parameter that kills the user’s custodian; and

- the snip-class-list, returned by get-the-snip-class-list is initialized with all of the snipclasses in DrRacket’s eventspace’s snip-class-list.

> procedure (drracket:eval:get-snip-classes)
> → (listof (is-a?/c snip-class%))

Returns a list of all of the snipclasses in the current eventspace.

> > procedure
> > (drracket:eval:expand-program |  | input |
> > |  | language-settings |
> > |  | eval-compile-time-part? |
> > |  | init |
> > |  | kill-termination |
> > |  | iter |
> > | [ | #:gui-modules? gui-modules?]) |
> → void?
> input : (or/c input-port? drracket:language:text/pos?)
> language-settings : drracket:language-configuration:language-settings?
> eval-compile-time-part? : boolean?
> init : (-> void?)
> kill-termination : (-> void?)
> | iter |  | : |  |
> (-> (or/c eof-object? syntax? (cons/c string? any/c))
> (-> any)
> any)
> gui-modules? : boolean? = #t

Use this function to expand the contents of the definitions window for use with external program processing tools.

This function uses drracket:eval:build-user-eventspace/custodian to build the user’s environment. The arguments language-settings, init, kill-termination, and gui-modules? are passed to drracket:eval:build-user-eventspace/custodian.

The input argument specifies the source of the program.

The eval-compile-time-part? argument indicates if expand is called or if expand-top-level-with-compile-time-evals is called when the program is expanded. Roughly speaking, if your tool will evaluate each expression itself by calling eval then pass #f. Otherwise, if your tool just processes the expanded program, be sure to pass #t.

This function calls front-end/complete-program to expand the program. Unlike when the Run is clicked, however, it does not call front-end/finished-complete-program.

The first argument to iter is the expanded program (represented as syntax) or eof. The iter argument is called for each expression in the expanded program and once more with eof, unless an error is raised during expansion. It is called from the user’s thread. If an exception is raised during expansion of the user’s program, iter is not called. Consider setting the exception-handler during init to handle this situation.

The second argument to iter is a thunk that continues expanding the rest of the contents of the definitions window. If the first argument to iter was eof, this argument is just the primitive void.

See also drracket:eval:expand-program/multiple.

> > procedure
> > (drracket:eval:traverse-program/multiple |
> > |  | language-settings |
> > |  | init |
> > |  | kill-termination |
> > | [ | #:gui-modules? gui-modules]) |
> | → |  |
> (-> (or/c input-port? drracket:language:text/pos?)
> (-> (or/c eof-object? syntax? (cons/c string? any/c))
> (-> any)
> any)
> boolean?
> void?)
> language-settings : drracket:language-configuration:language-settings?
> init : (-> void?)
> kill-termination : (-> void?)
> gui-modules : boolean? = #t

This function is similar to drracket:eval:expand-program/multiple The only difference is that it does not expand the program in the editor; instead the processing function can decide how to expand the program.

> > procedure
> > (drracket:eval:expand-program/multiple |
> > |  | language-settings |
> > |  | eval-compile-time-part? |
> > |  | init |
> > |  | kill-termination |
> > | [ | #:gui-modules? gui-modules?]) |
> | → |  |
> (-> (or/c input-port? drracket:language:text/pos?)
> (-> (or/c eof-object? syntax? (cons/c string? any/c))
> (-> any)
> any)
> boolean?
> void?)
> language-settings : drracket:language-configuration:language-settings?
> eval-compile-time-part? : boolean?
> init : (-> void?)
> kill-termination : (-> void?)
> gui-modules? : boolean? = #t

This function is just like drracket:eval:expand-program except that it is curried and the second application can be used multiple times. Use this function if you want to initialize the user’s thread (and namespace, etc) once but have program text that comes from multiple sources.

The extra boolean argument to the result function determines if drracket:language:language front-end/complete-program<%> or drracket:language:language front-end/interaction<%> is called.

> > procedure
> > (drracket:eval:build-user-eventspace/custodian |
> > |  | language-settings |
> > |  | init |
> > |  | kill-termination |
> > | [ | #:gui-modules? gui-modules?]) |
> | → |  |
> eventspace? |  | custodian?
> language-settings : drracket:language-configuration:language-settings?
> init : (-> void?)
> kill-termination : (-> void?)
> gui-modules? : boolean? = #t

This function creates a custodian and an eventspace (on the new custodian) to expand the user’s program. It does not kill this custodian, but it can safely be shutdown (with custodian-shutdown-all) after the expansion is finished.

It initializes the user’s eventspace’s main thread with several parameters:

- current-custodian is set to a new custodian.

- In addition, it calls drracket:eval:set-basic-parameters, passing the #:gui-modules? parameter along.

The language-settings argument is the current language and its settings. See drracket:language-configuration:language-settings for details on that structure.

If the program is associated with a DrRacket frame, get the frame’s language settings from the get-next-settings method of drracket:unit:definitions-text<%>. Also, the most recently chosen language in the language dialog is saved via the framework’s preferences. Apply preferences:get to drracket:language-configuration:get-settings-preferences-symbol for that language-settings.

The init argument is called after the user’s parameters are all set, but before the program is run. It is called on the user’s thread. The current-directory and current-load-relative-directory parameters are not set, so if there are appropriate directories, the init argument is a good place to set them.

The kill-termination argument is called when the main thread of the eventspace terminates, no matter if the custodian was shutdown, or the thread was killed. This procedure is also called when the thread terminates normally. This procedure is called from a new, dedicated thread (i. e., not the thread created to do the expansion, nor the thread that drracket:eval:build-user-eventspace/custodian was called from.)

top ← prev up next →