• Top
    • Documentation
    • Books
    • Recursion-and-induction
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
      • Theories
      • Rule-classes
      • Proof-builder
      • Hons-and-memoization
      • Events
      • History
      • Parallelism
      • Programming
      • Start-here
      • Real
      • Debugging
      • Miscellaneous
        • Term
        • Ld
        • Hints
        • Type-set
        • Ordinals
        • ACL2-customization
        • With-prover-step-limit
        • With-prover-time-limit
        • Set-prover-step-limit
        • Local-incompatibility
        • Set-case-split-limitations
        • Subversive-recursions
        • Specious-simplification
        • Defsum
        • Oracle-timelimit
        • Thm
        • Defopener
        • Gcl
        • Case-split-limitations
        • Set-gc-strategy
        • Default-defun-mode
        • Top-level
        • Reader
          • Sharp-f-reader
          • Fancy-string-reader
          • Sharp-u-reader
          • Sharp-dot-reader
          • Backquote
          • Sharp-bang-reader
        • Ttags-seen
        • Adviser
        • Ttree
        • Abort-soft
        • Defsums
        • Gc$
        • With-timeout
        • Coi-debug::fail
        • Expander
        • Gc-strategy
        • Coi-debug::assert
        • Sin-cos
        • Def::doc
        • Syntax
        • Subversive-inductions
      • Output-controls
      • Macros
      • Interfacing-tools
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
    • Testing-utilities
    • Math
  • Miscellaneous

Reader

Reading expressions in the ACL2 read-eval-print loop

The ACL2 read-eval-print loop reads expressions much like they are read in any Common Lisp read-eval-print loop. For example, you may use the single tick symbol (') for quote and also the backquote symbol (`) with its escapes, comma (,) and comma-atsign (,@). See any Common Lisp reference or tutorial.

ACL2-specific reader macros include its reading of expressions in a specified package (using #! — see sharp-bang-reader), its restriction of read-time evaluation to constants introduced by defconst (using #. — see sharp-dot-reader), and the ability to put underscores in numeric constants (using #u — see sharp-u-reader).

See set-iprint for how to make ACL2 print expressions like #@2# that can be read back in.

Strictly speaking, there is nothing special about how the reader handles keywords in the input. But see keyword-commands for how ACL2 may interpret a top-level keyword command.

We conclude this topic with a log that illustrates features discussed above. Comments of the form {{..}} have been inserted manually.

ACL2 !>(defconst *c* (+ 3 4))

Summary
Form:  ( DEFCONST *C* ...)
Rules: NIL
Time:  0.00 seconds (prove: 0.00, print: 0.00, other: 0.00)
 *C*
ACL2 !>'(a #.*c* 17)
;{{See :doc sharp-dot-reader.
;  Notice that #.*c* is read as the value of *c*, thus,
;  as 7 rather than as (+ 3 4).}}
(A 7 17)
ACL2 !>'(a #.(+ 5 6) 17)
;{{But this is not legal in ACL2, as #. must be followed by
;  a known constant symbol.}}

***********************************************
************ ABORTING from raw Lisp ***********
********** (see :DOC raw-lisp-error) **********
Error:  ACL2 supports #. syntax only for #.*a*, where *a* has been
defined by DEFCONST.  Thus the form #.(+ 5 6) is illegal.
***********************************************

;{{Additional output here has been omitted in this log.}}
ACL2 !>(defpkg "FOO" nil)

Summary
Form:  ( DEFPKG "FOO" ...)
Rules: NIL
Time:  0.00 seconds (prove: 0.00, print: 0.00, other: 0.00)
 "FOO"
ACL2 !>#!foo'(a b c)
;{{See :doc sharp-bang-reader.  The prefix "#!foo" causes
;  the s-expression after it to be read into the "FOO" package.}}
(FOO::A FOO::B FOO::C)
ACL2 !>#x100a
;{{As in Common Lisp, "#x" causes the digits after it to be read in hex.}}
4106
ACL2 !>#ux10_0a
;{{The "#u" prefix allows underscores in the numeral after it.  Those
;  underscores are ignored, but can improve readability.}}
4106
ACL2 !>(set-iprint t)
;{{See :DOC set-print.  This causes "#@1#" below to be printed.}}

ACL2 Observation in SET-IPRINT:  Iprinting has been enabled.
ACL2 !>(set-evisc-tuple (evisc-tuple 3   ; print-level
                                     4   ; print-length
                                     nil ; alist
                                     nil ; hiding-cars
                                     )
                        :sites :ld)
;{{Abbreviate the printing of top-level evaluation results.
;  See :doc set-evisc-tuple.}}
 (:LD)
ACL2 !>(make-list 10)
(NIL NIL NIL NIL . #@1#)
ACL2 !>'#@1#
;{{Note that the reader replaces #@1# with the value that was stored there.}}
(NIL NIL NIL NIL . #@2#)
ACL2 !>(without-evisc '(NIL NIL NIL NIL . #@1#))
;{{See :doc without-evisc.}}
(NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL)
ACL2 !>(set-evisc-tuple nil :sites :ld)
 (:LD)
ACL2 !>(let ((x '(3 4)))
         `(a b ,x c))
;{{As in Common Lisp, backquote can be escaped by comma.}}
(A B (3 4) C)
ACL2 !>(let ((x '(3 4)))
         `(a b ,@x c))
;{{As in Common Lisp, backquote can be escaped by comma-atsign, which
;  splices its value into the list.}}
(A B 3 4 C)
ACL2 !>

Subtopics

Sharp-f-reader
Read a rational number in floating-point (scientific notation) syntax
Fancy-string-reader
A friendly syntax for strings literals that have backslashes and quotes.
Sharp-u-reader
Allow underscore characters in numbers
Sharp-dot-reader
Read-time evaluation of constants
Backquote
Variant of quotation introducing templates for data structures
Sharp-bang-reader
Package prefix that is not restricted to symbols