Logos.Printer (Logos v0.2.0)

Copy Markdown

Logos.Printer.print/1 -- the textual printer. Every reader-producible type (numbers, strings, symbols, keywords, collections) must round-trip: print/1 followed by Logos.Reader.read/1 must yield an ==-equal value back. Runtime-only types (Pid, Atom, Fn) are exempt from that requirement -- they print informatively but have no reader syntax to read back into.

One deliberate, narrower exception: #inst/#uuid tagged literals (Logos.DataReaders, priv/grammar/logos.aether's tagged_literal rule) resolve to plain Logos strings, not a dedicated value type -- print/1 has no way to know a given string originated from #inst "..." rather than an ordinary "..." literal, so it prints back as an ordinary quoted string, not #inst "...". Unlike the Pid/Atom/Fn exemption above (a whole value type with no reader syntax at all), this is a narrower, string-specific round-trip gap -- see test/logos/reader_test.exs.

Every Logos.Form.t() case (the 14-case table in lib/logos/form.ex) prints in a shape Logos.Reader.read/1 can read back to an ==-equal value -- see test/logos/printer_test.exs for the actual round-trip proofs, one per reader-producible type, including nested/empty collections. The four runtime-only Logos.Value.t() cases (Fn, Atom, Pid, Transient) print in Clojure's own informative #<...> convention instead, deliberately not readable back (there is no reader syntax for any of them -- see Logos.Form.t()'s own moduledoc). SortedMap/SortedSet are a narrower case, same category as Record below: real reader-producible shapes ({...}/#{...}), just produced by a runtime-only value type rather than the reader itself -- they print exactly like an ordinary map/set (in sorted order), reading back as one, never round-tripping to their own sorted type (matching real Clojure).

Arbitrary-magnitude floats

Float.to_string/1 (the base of this module's float printing) falls back to scientific notation ("1.0e11") once the exponent gets large enough, and NUMBER's grammar (priv/grammar/logos.aether) reads that notation back (("e" | "E") ("+" | "-")? DIGIT+), so a very large/small float round-trips like everything else -- confirmed via test/logos/printer_test.exs's own round-trip proof for 1.0e300 and 1.0e-300, not just floats that happen to stay inside Float.to_string/1's plain-decimal range.

Summary

Functions

Prints value to its textual form.

Functions

print(n)

@spec print(term()) :: String.t()

Prints value to its textual form.