The arrow-macros Reference Manual

Table of Contents

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

The arrow-macros Reference Manual

This is the arrow-macros Reference Manual, generated automatically by Declt version 3.0 "Montgomery Scott" on Mon Apr 19 14:06:11 2021 GMT+0.


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

1 Introduction

Arrow-macros

Arrow-macros provides clojure-like arrow macros (ex. ->, ->>) and diamond wands in swiss-arrows (https://github.com/rplevy/swiss-arrows).

Build Status

Examples

(-> 1 (+ 2 3) #'1+ 1+ (lambda (x) (+ x 1)) (1+)) ; => 10
(->> (list 1 2 3 4 5)
  (mapcar #'1+)
  (reduce #'+)) ; => 20
(-<> "abcdefghijklmnopqrstuvwxyz"
  (ppcre:scan-to-strings "j.*q" <>)
  (sort #'string>)
  (string-upcase :end 1)) ; => "Qponmlkj"
(-> (get-some-webpage-uri id)
  drakma:http-request
  babel:octets-to-string
  json->list)

Installation

(ql:quickload :arrow-macros)

APIs

Clojure-like macros

These macro functions are equivalent to clojure's ones.

Diamond wands

These wonderful macros are developed in clojure's library swiss-arrows (https://github.com/rplevy/swiss-arrows). These macro functions are almost equivalent to them too.

(-<> 1 1+ #'1+ (1+) (lambda (x) (1+ x)))  ; => 5
(-<> 1
  (+ 2)     ; => (+ 1 2)
  (+ 3 <>)  ; => (+ 3 (+ 1 2))
  (+ 4)     ; => (+ (+ 3 (+ 1 2) 4)  => 10
(-<>> 1
  (+ 2)     ; => (+ 2 1)
  (+ <> 3)  ; => (+ (+ 2 1) 3)
  (+ 4)     ; => (+ 4 (+ (+ 2 1) 3)) => 10

Arrow-macros can also write nested diamond-wands like:

(-<>> (list 1 2 3)
  (mapcar #'1+)
  (-<> <> (sort #'>))
  (mapcar #'1+))       ; => (5 4 3)
(-<> 1 (+ <> <>) (-<> (+ <> <> <>)))  ; => 6

Be aware that the inner diamond-wand can refer to outer diamond symbol <> only in initial form.

Side effect in diamond wand and <!> symbol

Diamond wand can write multiple <> symbols in each expression.

(let ((x 0))
  (list (-<> x
          incf
          (+ <> <>)
          (+ <> <>))   ; => (+ (+ (incf x) (incf x)) (+ (incf x) (incf x))) => 10
        x))            ; => (10 4)
        

This means some expressions in diamond wands can be evaluated for 2 or more times. If you use expressions which have side effects in diamond wands, there is a risk that might happen what you don't intend. One solution is you don't use diamond wands for expressions containing side effects. Another solution is using <!> symbol in diamond wands. This may be a unique feature in this library. <!> symbol ensure previous expression evaluted only once.

(let ((x 0))
  (list (-<> x
          incf <!>
          (+ <> <>)
          (+ <> <>))
        x))            ; => (4 1)

(-<> (drakma:http-request <some-address>) <!>
  (some-converter <> :encode (detect-encoding-of <>)))  ; => this sends http request only once

Original library (https://github.com/rplevy/swiss-arrows) doesn't have this feature. I need this for my local small project so add it. It doesn't change the original diamond wand behavior but if you find any problems or improvements, please report me.

Notes

(Nov 26, 2020)

For author's misunderstading, diamond wand specification had been uncorrect (see issue #3). It has been fixed and the changes can make this library independence from code walker so arrow-macros is now smaller and slimer than old version.

(June 2015)

Build verified on sbcl, ccl, abcl, allegro, clisp. But diamond-wand tests fail on abcl, allegro, clisp. Failed on ecl while loading hu.dwim.walker. Not tested on cmucl. (contributed by guicho271828, thanks!)

(May 7, 2015)

On sbcl for windows, arrow-macros can be built now.

License

Arrow-macros is under the MIT License, see LICENSE file.


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 arrow-macros

Author

hipeta

License

MIT

Description

arrow-macros provides clojure-like arrow macros and diamond wands.

Dependency

alexandria

Source

arrow-macros.asd (file)

Component

arrow-macros.lisp (file)


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 arrow-macros.asd

Location

arrow-macros.asd

Systems

arrow-macros (system)

Packages

arrow-macros-asd


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

3.1.2 arrow-macros/arrow-macros.lisp

Parent

arrow-macros (system)

Location

arrow-macros.lisp

Packages

arrow-macros

Exported Definitions
Internal Definitions

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

4 Packages

Packages are listed by definition order.


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

4.1 arrow-macros-asd

Source

arrow-macros.asd

Use List

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

4.2 arrow-macros

Source

arrow-macros.lisp (file)

Use List

common-lisp

Exported Definitions
Internal Definitions

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

5 Definitions

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


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

5.1 Exported definitions


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

5.1.1 Macros

Macro: -<> INIT &body EXPS
Package

arrow-macros

Source

arrow-macros.lisp (file)

Macro: -<>> INIT &body EXPS
Package

arrow-macros

Source

arrow-macros.lisp (file)

Macro: -> INIT &body EXPS
Package

arrow-macros

Source

arrow-macros.lisp (file)

Macro: ->> INIT &body EXPS
Package

arrow-macros

Source

arrow-macros.lisp (file)

Macro: as-> INIT VAR &body EXPS
Package

arrow-macros

Source

arrow-macros.lisp (file)

Macro: cond-> INIT &body EXPS
Package

arrow-macros

Source

arrow-macros.lisp (file)

Macro: cond->> INIT &body EXPS
Package

arrow-macros

Source

arrow-macros.lisp (file)

Macro: some-<> INIT &body EXPS
Package

arrow-macros

Source

arrow-macros.lisp (file)

Macro: some-<>> INIT &body EXPS
Package

arrow-macros

Source

arrow-macros.lisp (file)

Macro: some-> INIT &body EXPS
Package

arrow-macros

Source

arrow-macros.lisp (file)

Macro: some->> INIT &body EXPS
Package

arrow-macros

Source

arrow-macros.lisp (file)


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

5.2 Internal definitions


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

5.2.1 Special variables

Special Variable: *diamond-wands*
Package

arrow-macros

Source

arrow-macros.lisp (file)


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

5.2.2 Functions

Function: arrow-macro INIT EXPS &optional >>-P SOME-P
Package

arrow-macros

Source

arrow-macros.lisp (file)

Function: cond-arrow-macro INIT EXPS &optional >>-P
Package

arrow-macros

Source

arrow-macros.lisp (file)

Function: diamond-wand INIT EXPS &optional >>-P SOME-P
Package

arrow-macros

Source

arrow-macros.lisp (file)

Function: diamond-wand% DIAMOND-EXP EXPS SOME-P
Package

arrow-macros

Source

arrow-macros.lisp (file)

Function: diamond-wand-symbol-p SYM
Package

arrow-macros

Source

arrow-macros.lisp (file)

Function: has-diamond EXP
Package

arrow-macros

Source

arrow-macros.lisp (file)

Function: replace-diamond EXP DIAMOND-EXP
Package

arrow-macros

Source

arrow-macros.lisp (file)


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

Appendix A Indexes


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

A.1 Concepts

Jump to:   A   F   L  
Index Entry  Section

A
arrow-macros.asd: The arrow-macros․asd file
arrow-macros/arrow-macros.lisp: The arrow-macros/arrow-macros․lisp file

F
File, Lisp, arrow-macros.asd: The arrow-macros․asd file
File, Lisp, arrow-macros/arrow-macros.lisp: The arrow-macros/arrow-macros․lisp file

L
Lisp File, arrow-macros.asd: The arrow-macros․asd file
Lisp File, arrow-macros/arrow-macros.lisp: The arrow-macros/arrow-macros․lisp file

Jump to:   A   F   L  

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

A.2 Functions

Jump to:   -  
A   C   D   F   H   M   R   S  
Index Entry  Section

-
-<>: Exported macros
-<>>: Exported macros
->: Exported macros
->>: Exported macros

A
arrow-macro: Internal functions
as->: Exported macros

C
cond->: Exported macros
cond->>: Exported macros
cond-arrow-macro: Internal functions

D
diamond-wand: Internal functions
diamond-wand%: Internal functions
diamond-wand-symbol-p: Internal functions

F
Function, arrow-macro: Internal functions
Function, cond-arrow-macro: Internal functions
Function, diamond-wand: Internal functions
Function, diamond-wand%: Internal functions
Function, diamond-wand-symbol-p: Internal functions
Function, has-diamond: Internal functions
Function, replace-diamond: Internal functions

H
has-diamond: Internal functions

M
Macro, -<>: Exported macros
Macro, -<>>: Exported macros
Macro, ->: Exported macros
Macro, ->>: Exported macros
Macro, as->: Exported macros
Macro, cond->: Exported macros
Macro, cond->>: Exported macros
Macro, some-<>: Exported macros
Macro, some-<>>: Exported macros
Macro, some->: Exported macros
Macro, some->>: Exported macros

R
replace-diamond: Internal functions

S
some-<>: Exported macros
some-<>>: Exported macros
some->: Exported macros
some->>: Exported macros

Jump to:   -  
A   C   D   F   H   M   R   S  

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

A.3 Variables

Jump to:   *  
S  
Index Entry  Section

*
*diamond-wands*: Internal special variables

S
Special Variable, *diamond-wands*: Internal special variables

Jump to:   *  
S  

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

A.4 Data types

Jump to:   A   P   S  
Index Entry  Section

A
arrow-macros: The arrow-macros system
arrow-macros: The arrow-macros package
arrow-macros-asd: The arrow-macros-asd package

P
Package, arrow-macros: The arrow-macros package
Package, arrow-macros-asd: The arrow-macros-asd package

S
System, arrow-macros: The arrow-macros system

Jump to:   A   P   S