Skip to content

SNIPPET

Martin Henz edited this page Aug 1, 2021 · 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
  • POSTPADDING: default: "yes", if "no", don't output any whitespace for padding after this SNIPPET. This is used when a SNIPPET is directly before another element which has a padding of its own.

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
  • SCHEMEPROMPT: the content is added to the comparison edition before the SCHEME program.
  • 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_PROMPT or JAVASCRIPT_OUTPUT) and (SCHEME or SCHEMEPROMPT or SCHEMEOUTPUT) are present, the online comparison edition shows a side-by-side view.

Tags within JAVASCRIPT include:

  • META: to print names in italics
  • METAPHRASE: to print phrases in italics and enclose them in angle brackets
  • SHORT_SPACE: to create some space between two lines, but less than a regular empty line
Clone this wiki locally