The reader Reference Manual

Next: , Previous: , Up: (dir)   [Contents][Index]

The reader Reference Manual

This is the reader Reference Manual, version 0.10.0, generated automatically by Declt version 4.0 beta 2 "William Riker" on Thu Sep 15 06:03:12 2022 GMT+0.

Table of Contents


1 Introduction

Installation

Download from the Releases section.

I'll promote v0.10.0 to v1.0.0 if there are no significant changes over the next year.

Getting Started

(reader:enable-reader-syntax &rest reader-macro-identifiers)
;; OR
(reader+swank:enable-package-local-reader-syntax &rest reader-macro-identifiers)
;; (describe 'reader:enable-reader-syntax) ; for a list of identifiers

;; Complementory macros
;; (reader:disable-reader-syntax) ; is complementary
;; OR
;; (reader+swank-disable-package-local-reader-syntax)

Examples

CL-USER> #[[1 2 3
            4 5 6]
           [3 2 1
            7 8 9]]
#3A(((1 2 3) (4 5 6)) ((3 2 1) (7 8 9)))        ; cleaner syntax for arrays
CL-USER> (gethash 'a {eq 'a 1 'b 2})            ; hash-tables
1
T
CL-USER> (hash-set:hs-memberp #{"a" "b" "c"} "c") ; hash-set - can change in future
T
CL-USER> [#2A((1 2 3) (4 5 6)) 1 0]             ; accessors
4
CL-USER> (setf reader:*get-val-array-function* 'select:select)
SLCT:SELECT
CL-USER> (let ((arr #2A((1 2 3) (4 5 6))))
           [arr t 0])
#(1 4)
CL-USER> [{"a" 1 "b" 2} "a"]
1
T
CL-USER> [(cl-json:decode-json-from-string "{\"a\":1, \"b\":2}") :b] ; works with alists
2
CL-USER> (-> {"a" "apple" "b" "ball"} ["b"] [1]); accessors can be chained using arrows:->
#\a
CL-USER> #!echo -n hello world
hello world                                     ; Captures until the end of line
NIL                                             ; Should be possible to capture into a string
NIL                                             ; but not ideal for speed
0
CL-USER> (let ((a t)) !a)                       ; not
NIL
CL-USER> (let ((a 5.0d0)) $a)                   ; write-to-string
"5.0d0"                   ; should this be "ensure-string"? raise an issue!
CL-USER> ?reader:enable-reader-syntax           ; variable use not intended
READER:ENABLE-READER-SYNTAX
  [symbol]
ENABLE-READER-SYNTAX names a macro:
  Lambda-list: (&REST READER::READER-MACRO-IDENTIFIERS)
  Documentation:
    READER-MACRO-IDENTIFIERS are any of the following symbols:
      GET-VAL, HASH-TABLE, NOT, STRING, DESCRIBE, ARRAY, SET, RUN-PROGRAM
  Source file: /home/user/quicklisp/local-projects/reader/reader.lisp

Notes

The functions used for constructing arrays, hash-tables, sets, accessing array elements or accessors in general can be specified by

This should allow users to use fset or access or other libraries for the respective functions.

By default, alists and plists are treated distinct from lists whenever possible (see the get-val method specialized on lists). To disable this behavior, set each of these to T:

Hash Tables

Setting alists and plists

array vs get-val

Notes for existing users upgrading to v0.10.0 from v0.9.1

Lambda

CL-USER> (mapcar λ(write-to-string -) '(2 3 4)) ; lambdas
("2" "3" "4")

This begins to feel like line-noise after a while and is not ideal for readability; a better equivalent is the simple macro

CL-USER> (defmacro lm (&rest var-body)
           `(lambda ,(butlast var-body)
              ,@(last var-body)))
LM
CL-USER> (mapcar (lm o (write-to-string o)) '(2 3 4))
("2" "3" "4")

Hash-table

Since the function used for constructing hash-tables is now configurable (via reader:*hash-table-function*), the first input to the hash-table may be interpreted as the equality function. Thus, hash-table syntax can take an even (with default test cl:equalp) or odd (with the first symbol being interpreted as the equality function) number of arguments.

Setting alists and plists

Now works for non-empty lists.

Testing

(ql:quickload "reader")
(5am:run :reader)
;; OR
(asdf:test-system "reader")

Emacs Indentation Support

(modify-syntax-entry ?\[ "(]" lisp-mode-syntax-table)
(modify-syntax-entry ?\] ")[" lisp-mode-syntax-table)
(modify-syntax-entry ?\{ "(}" lisp-mode-syntax-table)
(modify-syntax-entry ?\} "){" lisp-mode-syntax-table)
(define-key paredit-mode-map (kbd "{") 'paredit-open-curly)
(define-key paredit-mode-map (kbd "}") 'paredit-close-curly)
(global-set-key (kbd "C-S-l") (lambda () ; for inserting lambda
                                (interactive)
                                (insert-char (aref (symbol-name 'λ) 0))))
(setq paredit-space-for-delimiter-predicates
      (list (lambda (endp delimiter)
              (not (and (eql ?\( delimiter)
                        (member (char-before (point))
                                '(?\@ ?λ))))))))
(set-language-environment "UTF-8")

Motivation: paredit curly brace matching in swank-clojure repl - Stack OverFlow

Known Issues

Known issues include aligning hash-tables without first-element-as-key:

{"hello" 1
         "world" 2}

A work-around is to specify the test as the first element, and let that default exist for one-liners:

{equal "hello" 1
       "world" 2}
{"hello" 1 "world" 2}

Comments


2 Systems

The main system appears first, followed by any subsystem dependency.


Previous: , Up: Systems   [Contents][Index]

2.1 reader

A utility library intended at providing configurable reader macros for
common tasks such as accessors, hash-tables, sets, uiop:run-program, arrays and a few others.

Author

<Shubhamkar Ayare (shubhamayare@yahoo.co.in)>

License

MIT

Version

0.10.0

Dependencies
  • alexandria (system).
  • fiveam (system).
  • hash-set (system).
  • iterate (system).
  • split-sequence (system).
  • trivial-types (system).
  • uiop (system).
Source

reader.asd.

Child Component

reader.lisp (file).


3 Files

Files are sorted by type and then listed depth-first from the systems components trees.


Previous: , Up: Files   [Contents][Index]

3.1 Lisp


Next: , Previous: , Up: Lisp   [Contents][Index]

3.1.1 reader/reader.asd

Source

reader.asd.

Parent Component

reader (system).

ASDF Systems

reader.


Previous: , Up: Lisp   [Contents][Index]

3.1.2 reader/reader.lisp

Source

reader.asd.

Parent Component

reader (system).

Packages

reader.

Public Interface
Internals

4 Packages

Packages are listed by definition order.


Previous: , Up: Packages   [Contents][Index]

4.1 reader

Source

reader.lisp.

Use List
  • common-lisp.
  • hash-set.
  • iterate.
  • split-sequence.
Public Interface
Internals

5 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


Next: , Previous: , Up: Definitions   [Contents][Index]

5.1 Public Interface


Next: , Previous: , Up: Public Interface   [Contents][Index]

5.1.1 Special variables

Special Variable: *alists-are-lists*

If T, ALISTS will not be treated specially by READER:GET-VAL method for lists.

Package

reader.

Source

reader.lisp.

Special Variable: *array-function*

A symbol bound (at read-time) to a function that takes INITIAL-CONTENTS
as its argument and returns the array. INITIAL-CONTENTS is a list of nested-lists.

Package

reader.

Source

reader.lisp.

Special Variable: *get-val-array-function*

A symbol bound (at read-time) to a function that takes
(ARRAY &REST SUBSCRIPTS)
as arguments and returns the corresponding value.
This is assumed to have a SETF defined.
This variable is significant if READER:*GET-VAL-FUNCTION* is bound to READER:GET-VAL.

Package

reader.

Source

reader.lisp.

Special Variable: *get-val-function*

A symbol bound (at read-time) to a function that takes (OBJECT &REST KEY/S)
as arguments and returns the value corresponding to the KEY/S.

Package

reader.

Source

reader.lisp.

Special Variable: *hash-table-function*

A symbol bound (at read-time) to a function that takes (PLIST &KEY TEST)
as arguments and returns the hash-table.

Package

reader.

Source

reader.lisp.

Special Variable: *plists-are-lists*

If T, PLISTS will not be treated specially by READER:GET-VAL method for lists.

Package

reader.

Source

reader.lisp.

Special Variable: *set-function*

A symbol bound (at read-time) to a function that takes (LIST &KEY TEST)
as arguments and returns the set.

Package

reader.

Source

reader.lisp.


5.1.2 Macros

Macro: disable-reader-syntax ()
Package

reader.

Source

reader.lisp.

Macro: enable-reader-syntax (&rest reader-macro-identifiers)

READER-MACRO-IDENTIFIERS are any of the following symbols: GET-VAL, HASH-TABLE, NOT, STRING, DESCRIBE, ARRAY, SET, RUN-PROGRAM

Package

reader.

Source

reader.lisp.


Previous: , Up: Public Interface   [Contents][Index]

5.1.3 Generic functions

Generic Function: get-val (object &rest key/s)
Package

reader.

Source

reader.lisp.

Methods
Method: get-val ((object array) &rest key/s)
Method: get-val ((object list) &rest key/s)
Method: get-val ((object hash-table) &rest key/s)
Method: get-val ((object sequence) &rest key/s)
Method: get-val ((object structure-object) &rest key/s)
Generic Function: (setf get-val) (object &rest key/s)
Package

reader.

Methods
Method: (setf get-val) ((object array) &rest key/s)
Source

reader.lisp.

Method: (setf get-val) ((object list) &rest key/s)
Source

reader.lisp.

Method: (setf get-val) ((object standard-object) &rest key/s)
Source

reader.lisp.

Method: (setf get-val) ((object structure-object) &rest key/s)
Source

reader.lisp.

Method: (setf get-val) ((object sequence) &rest key/s)
Source

reader.lisp.

Method: (setf get-val) ((object hash-table) &rest key/s)
Source

reader.lisp.


5.2 Internals


Next: , Previous: , Up: Internals   [Contents][Index]

5.2.1 Constants

Constant: +reader-macro-doc+
Package

reader.

Source

reader.lisp.


Next: , Previous: , Up: Internals   [Contents][Index]

5.2.2 Special variables

Special Variable: *previous-readtables*
Package

reader.

Source

reader.lisp.

Special Variable: *reader-macro-activation-functions*
Package

reader.

Source

reader.lisp.


5.2.3 Macros

Macro: defmethods-with-setf (fun-name lambda-list &rest methods)
Package

reader.

Source

reader.lisp.

Macro: setp (new-value place)
Package

reader.

Source

reader.lisp.

Macro: with-env (&body body)
Package

reader.

Source

reader.lisp.

Macro: with-reader-syntax (reader-macro-identifiers &body body)

This macro is only made for use by read-and-eval functionality, and rather directed towards tests than users. So, do not export.

Package

reader.

Source

reader.lisp.


Previous: , Up: Internals   [Contents][Index]

5.2.4 Ordinary functions

Function: %enable-reader-syntax (readtable &rest reader-macro-identifiers)
Package

reader.

Source

reader.lisp.

Function: array-reader-macro (stream char n)
Package

reader.

Source

reader.lisp.

Function: describe-reader-macro (stream char)
Package

reader.

Source

reader.lisp.

Function: er (string)
Package

reader.

Source

reader.lisp.

Function: get-val-reader-macro (stream char)
Package

reader.

Source

reader.lisp.

Function: hash-table-reader-macro (stream char)
Package

reader.

Source

reader.lisp.

Function: list-to-hash-set-with-test (list &key test)
Package

reader.

Source

reader.lisp.

Function: make-t-array-from-initial-contents (initial-contents)
Package

reader.

Source

reader.lisp.

Function: not-reader-macro (stream char)
Package

reader.

Source

reader.lisp.

Function: read-array (stream)
Package

reader.

Source

reader.lisp.

Function: read-row-from-string (string)
Package

reader.

Source

reader.lisp.

Function: read-stream-as-string-until (stream until-char)
Package

reader.

Source

reader.lisp.

Function: read-stream-until (stream until-char)
Package

reader.

Source

reader.lisp.

Function: run-program-reader-macro (stream char n)
Package

reader.

Source

reader.lisp.

Function: set-reader-macro (stream char n)
Package

reader.

Source

reader.lisp.

Function: string-reader-macro (stream char)
Package

reader.

Source

reader.lisp.


Appendix A Indexes


Next: , Previous: , Up: Indexes   [Contents][Index]

A.1 Concepts


Next: , Previous: , Up: Indexes   [Contents][Index]

A.2 Functions

Jump to:   %   (  
A   D   E   F   G   H   L   M   N   R   S   W  
Index Entry  Section

%
%enable-reader-syntax: Private ordinary functions

(
(setf get-val): Public generic functions
(setf get-val): Public generic functions
(setf get-val): Public generic functions
(setf get-val): Public generic functions
(setf get-val): Public generic functions
(setf get-val): Public generic functions
(setf get-val): Public generic functions

A
array-reader-macro: Private ordinary functions

D
defmethods-with-setf: Private macros
describe-reader-macro: Private ordinary functions
disable-reader-syntax: Public macros

E
enable-reader-syntax: Public macros
er: Private ordinary functions

F
Function, %enable-reader-syntax: Private ordinary functions
Function, array-reader-macro: Private ordinary functions
Function, describe-reader-macro: Private ordinary functions
Function, er: Private ordinary functions
Function, get-val-reader-macro: Private ordinary functions
Function, hash-table-reader-macro: Private ordinary functions
Function, list-to-hash-set-with-test: Private ordinary functions
Function, make-t-array-from-initial-contents: Private ordinary functions
Function, not-reader-macro: Private ordinary functions
Function, read-array: Private ordinary functions
Function, read-row-from-string: Private ordinary functions
Function, read-stream-as-string-until: Private ordinary functions
Function, read-stream-until: Private ordinary functions
Function, run-program-reader-macro: Private ordinary functions
Function, set-reader-macro: Private ordinary functions
Function, string-reader-macro: Private ordinary functions

G
Generic Function, (setf get-val): Public generic functions
Generic Function, get-val: Public generic functions
get-val: Public generic functions
get-val: Public generic functions
get-val: Public generic functions
get-val: Public generic functions
get-val: Public generic functions
get-val: Public generic functions
get-val-reader-macro: Private ordinary functions

H
hash-table-reader-macro: Private ordinary functions

L
list-to-hash-set-with-test: Private ordinary functions

M
Macro, defmethods-with-setf: Private macros
Macro, disable-reader-syntax: Public macros
Macro, enable-reader-syntax: Public macros
Macro, setp: Private macros
Macro, with-env: Private macros
Macro, with-reader-syntax: Private macros
make-t-array-from-initial-contents: Private ordinary functions
Method, (setf get-val): Public generic functions
Method, (setf get-val): Public generic functions
Method, (setf get-val): Public generic functions
Method, (setf get-val): Public generic functions
Method, (setf get-val): Public generic functions
Method, (setf get-val): Public generic functions
Method, get-val: Public generic functions
Method, get-val: Public generic functions
Method, get-val: Public generic functions
Method, get-val: Public generic functions
Method, get-val: Public generic functions

N
not-reader-macro: Private ordinary functions

R
read-array: Private ordinary functions
read-row-from-string: Private ordinary functions
read-stream-as-string-until: Private ordinary functions
read-stream-until: Private ordinary functions
run-program-reader-macro: Private ordinary functions

S
set-reader-macro: Private ordinary functions
setp: Private macros
string-reader-macro: Private ordinary functions

W
with-env: Private macros
with-reader-syntax: Private macros

Jump to:   %   (  
A   D   E   F   G   H   L   M   N   R   S   W