Skip to content

SNIPPET

martin-henz edited this page Nov 18, 2020 · 17 revisions

Attributes of SNIPPET include:

  • EVAL: default: "yes", if "no": no link to a runnable program is generated.
  • LATEX: default: "no", if "yes": the body contains LaTeX formulas (enclosed in $)
  • HIDE: default: "no", if "yes": do not include this snippet in any output

Tags within SNIPPET include:

  • NAME: string by which SNIPPETs can refer to each other, using REQUIRES and EXAMPLE
  • REQUIRES: the name of another SNIPPET, which is recursively included in the runnable program. Limitation: SNIPPETs with REQUIRES tags must have a NAME tag. The graph created by REQUIRES tags must be acyclic. The algorithm performs DFS and includes each SNIPPET at most once.
  • EXPECTED: If a SNIPPET s has an EXPECTED tag, the content of the EXPECTED tag is appended in comment for the generated file for auto-testing, see yarn test; the comment has the shape: // expected: EXPECTED where EXPECTED is the string in the EXPECTED tag.
  • EXAMPLE: the name of another SNIPPET. The source content of that SNIPPET is included after all REQUIRES SNIPPETs in the runnable program; note that the REQUIRES SNIPPETs of the EXAMPLE snippet are processed as if they were REQUIRES SNIPPETs of the SNIPPET that contains the EXAMPLE tag. (In particular, the EXAMPLE snippet can include the SNIPPET in which the EXAMPLE tag occurs, using REQUIRES, without causing an infinite loop.)
  • JAVASCRIPT: the JavaScript source for display. In the runnable program, REQUIRE snippets are recursively added, see REQUIRES above.
  • JAVASCRIPT_RUN: the JavaScript source for running by clicking on textbook entries in the online and comparison editions. Overrides JAVASCRIPT if present. In the runnable program, REQUIRES snippets are recursively added, see REQUIRES above.
  • JAVASCRIPT_TEST: the JavaSCript source for testing programs with yarn test. Overrides JAVASCRIPT and JAVASCRIPT_RUN if present. In the runnable program, REQUIRES snippets are recursively added, see REQUIRES above.
  • JAVASCRIPT_OUTPUT: the content is added to the PDF version in italics after the program, similar to the original SICP; also shows in comparison edition
  • JAVASCRIPT_PROMPT: the content is added to the PDF version in italics before the program, similar to the original SICP; also shows in comparison edition
  • JAVASCRIPT_LONELY: the content is added to the PDF version in italics, similar to the original SICP; also shows in comparison edition; spacing such that there is no JAVASCRIPT tag
  • SCHEME: the Scheme source for display in the comparison edition
  • SCHEMEOUTPUT: the content is added to the comparison edition after the SCHEME program.

If (JAVASCRIPT or JAVASCRIPT_OUTPUT) and (SCHEME or SCHEMEOUTPUT) are present, the online comparison edition shows a side-by-side view.

Clone this wiki locally