Feedback for glossary entry on formatting/print/write/display

Here is a different way to think about how this works:

  • evaluating (with-input-from-string "foo" read) returns an internal data structure, a Scheme symbol type, whose name is foo
  • you could pass this Scheme symbol to eval, who will return the value associated with the symbol (or raise an exception if the symbol foo is not bound)
  • you could also pass this internal structure to print which will create a text representation of this, which is the text 'foo, which is what you see in the Racket console.

Why does print prepend a quote to the symbol name when it is asked to print a symbol? Because print assumes the text will be an input to a read-eval-print loop. Here is how that would work:

  • user types the text 'foo at the prompt
  • read reads this text as (quote foo) (a list whose first element is the symbol quote and the second element is the symbol foo
  • the (quote foo) list is passed to eval which evaluates it, producing the Scheme symbol whose name is foo
  • This Scheme symbol is than passed to print which prints it out as the text 'foo

Alex.

3 Likes