Embedding

An embeddable version of this interpreter is available at http://scheme.cs61a.org/embed.html.

You could include it in a webpage with something like this:

<iframe src="http://scheme.cs61a.org/embed.html"
        style="width: 650px; height: 400px"
        frameborder="0"></iframe>

The embedded version will not save history or themes between sessions and will only focus the input box after the user clicks inside the frame.

You can configure it with the following URL parameters. These URL parameters will also work with the regular interpreter, but are particularly important for the embedded version.

When adding URL parameters, it is recommended to put a # before the question mark, as this will allow browsers to load the interpreter from the cache regardless of the parameters.

While URL parameters are cleared on the regular interpreter when (exit) is called, calling (exit) from an embedded interpreter will reload the page with the same URL parameters (essentially resetting it to its initial state).

theme, background, and foreground

The theme parameter loads the provided theme as if the user had entered (theme 'theme-name) into the interpreter. Available themes are listed in the main help document.

If the theme parameter is not set and either (or both) of the background and foreground parameters are, then the monochrome theme will be loaded with the given colors. The ui-monochrome procedure that is usually bound by the monochrome theme will then be removed.

zoom

This parameter sets the zoom of all elements on the page to the given value. For example zoom=0.5 would be everything half as big while zoom=2 would make everything twice as big. Zoom can also be set with the zoom built-in procedure.

Please note that setting zoom to be less than 0.55 can cause some issues when diagramming.

library and demo

These parameters will load one or more libraries or demos (separated by commas) as if the user had entered (library 'name) or (demo 'name) for each library or demo. These will load mostly silently. Any calls to display or print within the library or demo will still be output, but the list of names bound will not be outputted.

run

This parameter can contain any arbitrary Scheme code, which will be outputted to the log as if the user had entered it themselves. Calls separated by line breaks (encoded in a URL as %0A) will be entered sequentially (as if the user had entered each line separately).

Make sure to URL encode your code.

Web Component

You can also embed the interpreter as a web component. You'll need a polyfill (at least as long as Chrome is the only browser with native support) and the Scheme component I've created:

<script src="//cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/0.7.21/webcomponents-lite.min.js"></script>
<script src="//scheme.cs61a.org/js/scheme-component.js"></script>

You can then embed an interpreter with:

<scheme-interpreter>
; code here will be put in the run parameter
(+ 1 2)
</scheme-interpreter>

You can set default values for width, height or any of the parameters above (except for run) by adding them to the SchemeDefaults object before loading the component, or add them as HTML attributes.

Examples

Web Component:

<scheme-interpreter theme='solarized' width='650px' height='400px'>
(+ 4 5)
(draw-pair '(1 (2 (3 4) 5) 6))
</scheme-interpreter>

iframe:

<iframe src="http://scheme.cs61a.org/embed.html#?theme=solarized&run=(%2B%204%205)%0A(draw-pair%20%27(1%20(2%20(3%204)%205)%206))"
        style="width: 650px; height: 400px"
        frameborder="0"></iframe>

Web Component:

<scheme-interpreter background='navy' foreground='white' zoom='0.7'
                    demo='diagram' width='650px' height='500px'>
(visualize (fact 3))
(vis-goto 8)
</scheme-interpreter>

iframe:

<iframe src="http://scheme.cs61a.org/embed.html#?background=navy&foreground=white&zoom=0.7&demo=diagram&run=(visualize%20(fact%203))%0A(vis-goto%208)"
        style="width: 650px; height: 500px"
        frameborder="0"></iframe>