The curry-compose-reader-macros Reference Manual

Table of Contents

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

The curry-compose-reader-macros Reference Manual

This is the curry-compose-reader-macros Reference Manual, version 1.0.0, generated automatically by Declt version 3.0 "Montgomery Scott" on Wed Mar 25 17:54:48 2020 GMT+0.


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

1 Introduction

CURRY-COMPOSE-READER-MACROS

Reader macros for concise expression of function partial application and composition.

These reader macros expand into the curry, rcurry and compose functions from the Alexandria library. The contents of curly brackets are curried and the contents of square brackets are composed. The _ symbol inside curly brackets changes the order of arguments with rcurry.

The following examples demonstrate usage.

;; partial application `curry'
(mapcar {+ 1} '(1 2 3 4)) ; => (2 3 4 5)

;; alternate order of arguments `rcurry'
(mapcar {- _ 1} '(1 2 3 4)) ; => (0 1 2 3)

;; function composition
(mapcar [#'list {* 2}] '(1 2 3 4)) ; => ((2) (4) (6) (8))

Additionally, special brackets may be used to split arguments amongst a list of functions and collect the results. The first element of the «»-delimited list is the "join" function. Incoming arguments are split out to the remaining functions in the «»-delimited list, and their results are then passed to the join function. (Emacs users can type « and » with C-x 8 < and C-x 8 > respectively)

;; function split and join
(mapcar «list {* 2} {* 3}» '(1 2 3 4)) ; => ((2 3) (4 6) (6 9) (8 12))
(mapcar «and {< 2} #'evenp» '(1 2 3 4)) ; => (NIL NIL NIL T)
(mapcar «+ {* 2} {- _ 1}» '(1 2 3 4)) ; => (2 5 8 11)

Finally, and this is probably too much, even more special brackets can be useful for generating cond/case forms. This can be useful for processing lists of heterogeneous types. For case (not cond) forms, the first element of the ‹›-delimited list is the case "keyform." The other elements are two-element cond/case clauses in which the first is the guard, and the second is the value. Elements of the guard are evaluated at read time to determine if they are functions which should be applied, or literals which should be included verbatim--this could be dangerous in some cases so beware.

;; concise case expressions
(mapcar ‹typecase (number #'1+) (string :str)› '(1 "this" 2 "that"))
                                        ; => (2 :STR 3 :STR)
(mapcar ‹cond (#'evenp {+ 100}) (#'oddp {+ 200})› '(1 2 3 4))
                                        ; => (201 102 203 104)
;; also if/when/unless support
(mapcar ‹if #'evenp #'1+ #'1-› '(1 2 3 4)) ; => (0 3 2 5)

Load CURRY-COMPOSE-READER-MACROS at the REPL with the following

(ql:quickload :curry-compose-reader-macros)
(ql:quickload :named-readtables)
(use-package 'named-readtables)
(in-readtable :curry-compose-reader-macros)

Use CURRY-COMPOSE-READER-MACROS in source by adding NAMED-READTABLES and CURRY-COMPOSE-READER-MACROS to your ASDF file and package and then including the following in source files which use these reader macros.

(in-readtable :curry-compose-reader-macros)

Emacs users may easily treat {}'s, []'s, «»'s, and ‹›'s as parenthesis for paredit commands and SEXP movement with the following configuration.

;; Syntax table
(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)
(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)

;; Paredit keys
(eval-after-load "paredit"
  '(progn
    (define-key paredit-mode-map "[" 'paredit-open-parenthesis)
    (define-key paredit-mode-map "]" 'paredit-close-parenthesis)
    (define-key paredit-mode-map "(" 'paredit-open-bracket)
    (define-key paredit-mode-map ")" 'paredit-close-bracket)
    (define-key paredit-mode-map "«" 'paredit-open-special)
    (define-key paredit-mode-map "»" 'paredit-close-special)
    (define-key paredit-mode-map "‹" 'paredit-open-special)
    (define-key paredit-mode-map "›" 'paredit-close-special)))

Also, Emacs will insert « with C-x 8 < and » with C-x 8 >. Emacs can be instructed to define similar key-bindings for with the following:

(global-set-key (kbd "\C-x 8 (") (lambda () (interactive) (insert-char #x2039)))
(global-set-key (kbd "\C-x 8 )") (lambda () (interactive) (insert-char #x203A)))

which will cause Emacs to insert


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

2 Systems

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


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

2.1 curry-compose-reader-macros

Author

Eric Schulte <schulte.eric@gmail.com>

License

Public Domain

Description

reader macros for concise function partial application and composition

Version

1.0.0

Dependencies
Source

curry-compose-reader-macros.asd (file)

Components

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

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 files   [Contents][Index]

3.1.1 curry-compose-reader-macros.asd

Location

curry-compose-reader-macros.asd

Systems

curry-compose-reader-macros (system)


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

3.1.2 curry-compose-reader-macros/package.lisp

Parent

curry-compose-reader-macros (system)

Location

package.lisp

Packages

curry-compose-reader-macros


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

3.1.3 curry-compose-reader-macros/curry-compose-reader-macros.lisp

Dependency

package.lisp (file)

Parent

curry-compose-reader-macros (system)

Location

curry-compose-reader-macros.lisp

Internal Definitions

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

4 Packages

Packages are listed by definition order.


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

4.1 curry-compose-reader-macros

Source

package.lisp (file)

Use List
Internal Definitions

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

5 Definitions

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


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

5.1 Internal definitions


Previous: , Up: Internal definitions   [Contents][Index]

5.1.1 Functions

Function: langle-quotation-reader STREAM INCHAR
Package

curry-compose-reader-macros

Source

curry-compose-reader-macros.lisp (file)

Function: lcurly-brace-reader STREAM INCHAR
Package

curry-compose-reader-macros

Source

curry-compose-reader-macros.lisp (file)

Function: lsingle-pointing-angle-quotation-mark-reader STREAM INCHAR
Package

curry-compose-reader-macros

Source

curry-compose-reader-macros.lisp (file)

Function: lsquare-brace-reader STREAM INCHAR
Package

curry-compose-reader-macros

Source

curry-compose-reader-macros.lisp (file)


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

Appendix A Indexes


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

A.1 Concepts

Jump to:   C   F   L  
Index Entry  Section

C
curry-compose-reader-macros.asd: The curry-compose-reader-macros․asd file
curry-compose-reader-macros/curry-compose-reader-macros.lisp: The curry-compose-reader-macros/curry-compose-reader-macros․lisp file
curry-compose-reader-macros/package.lisp: The curry-compose-reader-macros/package․lisp file

F
File, Lisp, curry-compose-reader-macros.asd: The curry-compose-reader-macros․asd file
File, Lisp, curry-compose-reader-macros/curry-compose-reader-macros.lisp: The curry-compose-reader-macros/curry-compose-reader-macros․lisp file
File, Lisp, curry-compose-reader-macros/package.lisp: The curry-compose-reader-macros/package․lisp file

L
Lisp File, curry-compose-reader-macros.asd: The curry-compose-reader-macros․asd file
Lisp File, curry-compose-reader-macros/curry-compose-reader-macros.lisp: The curry-compose-reader-macros/curry-compose-reader-macros․lisp file
Lisp File, curry-compose-reader-macros/package.lisp: The curry-compose-reader-macros/package․lisp file

Jump to:   C   F   L  

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

A.2 Functions

Jump to:   F   L  
Index Entry  Section

F
Function, langle-quotation-reader: Internal functions
Function, lcurly-brace-reader: Internal functions
Function, lsingle-pointing-angle-quotation-mark-reader: Internal functions
Function, lsquare-brace-reader: Internal functions

L
langle-quotation-reader: Internal functions
lcurly-brace-reader: Internal functions
lsingle-pointing-angle-quotation-mark-reader: Internal functions
lsquare-brace-reader: Internal functions

Jump to:   F   L  

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

A.3 Variables


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

A.4 Data types

Jump to:   C   P   S  
Index Entry  Section

C
curry-compose-reader-macros: The curry-compose-reader-macros system
curry-compose-reader-macros: The curry-compose-reader-macros package

P
Package, curry-compose-reader-macros: The curry-compose-reader-macros package

S
System, curry-compose-reader-macros: The curry-compose-reader-macros system

Jump to:   C   P   S