Function Entry: READ

← Prev | ↑ Chapter | Next → | Index | Symbols

Function Entry: READ

Name

read

Class

Function

Syntax

(read [string])

Arguments and Values

  • string (optional): a text value to parse. Both vendor pages note it "should not contain blanks, except within a list or string" — parsing stops at the first delimiter (blank, newline, tab, or a matched form). Omitted: BricsCAD's page documents this as returning nil; AutoCAD's page does not name the omitted-argument case explicitly.

Description

Parses the first AutoLISP expression represented in string and returns it, converted to the corresponding AutoLISP data type (integer, real, list, symbol, string, file, T, or nil).

Return Values

Returns the first object read from the string, or nil if none is found (empty/whitespace-only input, or — see Notes — a string whose first non-blank content is a comment, depending on dialect).

Examples

  • (read "hello") -> HELLO
  • (read "(a b c)") -> (A B C)
  • (read "1.2300") -> 1.23

Notes

read is the main vendor-documented entry point into surface syntax behavior, but neither vendor's own read reference page says anything at all about comment-handling in the string argument — comments are documented only on a separate, generically-titled Autodesk page framed around program files ("About Comments in AutoLISP Program Files"), not around read on a bare string. In the absence of a spec, the two real engines do not even agree with EACH OTHER:

Tested Behaviour (product-tested, 2026-09-08 — see the issue below)

A string whose first non-blank content is a comment, before any real object — whether a ; line comment or a ;| … |; block comment — is handled differently by every engine tested:

Engine leading LINE comment (;) leading BLOCK comment
BricsCAD (V25 Windows, V26 macOS) returns NIL returns NIL
AutoCAD 2022 (Windows) skips it, returns the object returns NIL
clautolisp (its own default) skips it, returns the object skips it, returns the object

(the BLOCK-comment column is the ;| … |; form)

So BricsCAD returns NIL the instant the first non-blank thing its reader meets is any comment, of either kind, before any real object. AutoCAD only does that for a block comment — a leading line comment is skipped exactly like load would skip it. clautolisp's own reader is uniformly lenient for both. (Trailing comments — after the first object, or between repeated read calls on one string — are not characterized here.)

Per-dialect behavior (clautolisp 2.1.1+)

clautolisp reproduces this per –dialect, and emits an advisory [read-leading-comment] dialect-portability warning (autolisp-spec ch. 25) wherever the effective behavior is a hazard on a real engine:

  • –dialect bricscad: returns NIL for a leading comment of either kind (matching real BricsCAD exactly) and warns for both.
  • –dialect autocad: skips a leading line comment silently (matches real AutoCAD and clautolisp's own default); returns NIL and warns for a leading block comment (matching real AutoCAD).
  • –strict: keeps clautolisp's lenient skip-and-return behavior for both kinds, but warns for both — strict names no vendor, and at least one real engine disagrees either way.
  • –dialect clautolisp / –lax: silently lenient for both kinds, unchanged — the same convenience already granted to every other clautolisp-only leniency.

Availability

  • AutoCAD 2026: documented (per Autodesk reference page). Comment handling: undocumented; product-tested as of the AutoCAD 2022 release (see Tested Behaviour above).
  • BricsCAD V26: documented (Bricsys DevRef page). Comment handling: undocumented; product-tested against V25 (Windows) and V26 (macOS).
  • Status: documented by both vendors for the basic contract; comment handling is an undocumented, vendor-divergent behavior established by live product testing, not by either reference page.

Source Notes

Tested Behaviour (sunset campaign B3, 2026-10-28)

probe-reader-printer.lsp; AutoCAD 2022 job 17540963671, BricsCAD V25 Windows 17540963675, BricsCAD V26 macOS 17540963672. "both" = AutoCAD and BricsCAD alike.

input AutoCAD 2022 BricsCAD V25 / V26
"1e3", "1E+03" 1000.0 1000.0
"1.", "1.e6" 1.0, 1000000.0 the same
".5" error (misplaced dot) syntax error
"+.5", "-.5" the symbol + / - the symbol +.5 / -.5
"1.5.2" the symbol 1 the symbol 1.5.2
"a.b", "(a.b)" A, (A) A.B, (A.B)
"A\101B", "A\377B" AAB, A<255>B (octal) the same
"A\x41B", "A\qB" Ax41B, AqB (backslash dropped) the same
"A\u0041B" Auu0041B AU0041B
"A\0B" A (the string ends) A<0><0>

Comments: (read "1 ; two") is 1 on both, and so is a block comment between two tokens; but a block comment BEFORE the token, (read ";| c |; 3"), gives 3 on AutoCAD and nil on BricsCAD. The symbol tokens a#b, a[b], a:b, a,b read as one symbol each on both; |a b| reads as the symbol named "|A" and a'b as A on both.

clautolisp: READ

Exponent reals without a dot (1e3) are reals, octal escapes are decoded and any other unknown escape drops its backslash, in every dialect, as both products (2.3.76; before: a symbol, and the backslash kept). The product differences above – ".5" accepted as 0.5, the AutoCAD readings of +.5, 1.5.2, a.b and a leading block comment, \u and \0 – are not modelled yet: issues/open/reader-printer-vendor-divergences.issue.