The glyphs Reference Manual

Table of Contents

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

The glyphs Reference Manual

This is the glyphs Reference Manual, generated automatically by Declt version 2.3 "Robert April" on Wed Mar 14 03:58:37 2018 GMT+0.


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

1 Introduction

glyphs

A little experiment in reducing verbosity in Common Lisp, inspired by BODOL (https://github.com/bodil/BODOL - no affiliation).

To try it out in your REPL you can use (ql:quickload :glyphs) if you have added to your ASDF load path in local projects.

Update: Now that it's in quicklisp, simply:

(ql:quickload :glyphs)

Examples

Factorial example with glyphs function macro:

glyphs:

(ƒ factorial
   0 → 1
   α → (* α (factorial (1- α))))

vs.:

(defun factorial (x)
  (cond ((equal x 0) 1)
        (x (* x (factorial (1- x))))))

result:

(factorial 8)
40320

Type safety with factorial

(ƒ factorial
  0 → 1
  (and (numberp α) (> α 0)) → (* α (factorial (1- α)))
  α → (error "Non-numbers (or negatives) don't work real well with factorials!"))

vs.:

(defun factorial (x)
  (cond ((equal x 0) 1)
        ((and (numberp x) (> x 0)) (* x (factorial (1- x))))
        (t (error "Non-numbers (or negatives) don't work real well with factorials!"))))

Built in type safety with factorial

(ƒ→ factorial (integer → integer)
  0 → 1
  α → (* α (factorial (1- α))))

Reverse a list

glyphs:

(ƒ reverse*
  (cdr α) → (append (reverse* (cdr α)) `(,(car α)))
  α → α)

Map with glyphs lambda macro to compare strings and do a side effect

glyphs:

(mapcar (λ "cat" → (print "Cats rock")
           "dog" → (print "Dogs do too!")) '("cat" "dog" "mouse"))

vs.:

(mapcar (lambda (x)
          (cond ((equal x "cat") (print "Cats rock"))
                ((equal x "dog") (print "Dogs do too!")) '("cat" "dog" "mouse"))))

result:

"Cats rock"
"Dogs do too!"
NIL

Comparison based on passed in conditionals

glyphs:

(ƒ double-odds-half-evens
  (oddp α) → (* x 2)
  (evenp α) → (/ x 2))

vs.:

(defun double-odds-half-evens (x)
  (cond ((oddp x) (* x 2))
        ((evenp x) (/ x 2))))

result:

(double-odds-half-evens 4)
2
(double-odds-half-evens 3)
6

Using multiple values by including special variables in the statement

You can use multiple values by prefixing a variable in the statement portion of the code with either a 'α' or an '?'.

glyphs:

(mapcar (λ α → (+ α αb αc)) '(1 2 3) '(4 5 6) '(7 8 9))

vs.:

(mapcar (lambda (a b c) (+ a b c)) '(1 2 3) '(4 5 6) '(7 8 9))

result:

(12 15 18)

Fast matching based on regex strings

Make sure to use the readtable that comes with it first:

(in-readtable glyphs:syntax)

Or these little readtable shortcuts will not work.

glyphs:

(ƒ any-cats?
  ~"cat"~ → (print "yes!"))

vs.:

(defun any-cats? (x)
  (when (cl-ppcre:scan "cat" x)
    (print "yes!")))

result:

(any-cats? "I see some cats")
"yes!"

Easy regex replaces on matching strings

glyphs:

(ƒ no-cats
  ~"(were|cat)"~ → |"dog"|)

vs.:

(defun no-cats (x)
  (let ((regex "(were|cat)"))
       (when (cl-ppcre:scan regex x)
         (cl-ppcre:regex-replace-all regex x "dog"))))

result:

(no-cats "there were dogs and there were cats")
"there dog dogs and there dog dogs"

Currently used glyphs and bindings for them (more to come)

Emacs bindings

Add to `.emacs'

;; Keybindings for glyphs
(global-set-key (kbd "M-l") (lambda () (interactive) (insert "\u03bb"))) ; λ lambda
(global-set-key (kbd "M-f") (lambda () (interactive) (insert "\u0192"))) ; ƒ function
(global-set-key (kbd "M--") (lambda () (interactive) (insert "\u2192"))) ; → right arrow
(global-set-key (kbd "M-a") (lambda () (interactive) (insert "\u03b1"))) ; α alpha
(global-set-key (kbd "M-y") (lambda () (interactive) (insert "\u03c8"))) ; ψ psi

Vim bindings

Add to `.vimrc'

" Keybindings for glyphs
:inoremap <A-l> <C-v>u3bb<Space>   ; λ lambda
:inoremap <A-f> <C-v>u192<Space>   ; ƒ function
:inoremap <A--> <C-v>u2192<Space>  ; → right arrow
:inoremap <A-a> <C-v>u03b1<Space>  ; α alpha
:inoremap <A-y> <C-v>u03c8<Space>  ; ψ psi

Mac OS X keybindings

Add to `~/Library/KeyBindings/DefaultKeyBinding.dict'

{
"~l" = ("insertText:", "\U03BB"); /* alt + l ~> λ lambda */
"~f" = ("insertText:", "\U0192"); /* alt + f ~> ƒ function */
"~-" = ("insertText:", "\U2192"); /* alt + - ~> → right arrow */
"~a" = ("insertText:", "\U03b1"); /* alt + a ~> α alpha */
"~y" = ("insertText:", "\U03c8"); /* alt + y ~> ψ psi */
}

StumpWM keybindings

(defmacro defkeys-top (&rest keys)
  (let ((ks (mapcar #'(lambda (k) (cons 'defkey-top k)) keys)))
    `(progn ,@ks)))

(defcommand xdo-lambda () ()
    (run-shell-command "xdotool type λ"))
(defcommand xdo-fn () ()
    (run-shell-command "xdotool type ƒ"))
(defcommand xdo-alpha () ()
    (run-shell-command "xdotool type α"))
(defcommand xdo-arrow () ()
    (run-shell-command "xdotool type →"))

(defkeys-top
    ("s-l" "xdo-lambda")
    ("s-f" "xdo-fn")
    ("s--" "xdo-arrow")
    ("s-a" "xdo-alpha"))

If you're absolutely opposed to non-asc


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 glyphs

Author

Matthew Carter <m@ahungry.com>

License

GPLv3

Description

Glyphs to reduce Common Lisp verbosity

Dependencies
Source

glyphs.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 glyphs.asd

Location

glyphs.asd

Systems

glyphs (system)


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

3.1.2 glyphs/package.lisp

Parent

glyphs (system)

Location

package.lisp

Packages

glyphs


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

3.1.3 glyphs/glyphs.lisp

Dependency

package.lisp (file)

Parent

glyphs (system)

Location

glyphs.lisp

Exported Definitions
Internal Definitions

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

4 Packages

Packages are listed by definition order.


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

4.1 glyphs

Source

package.lisp (file)

Use List
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


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

5.1.1 Special variables

Special Variable: *ψ*
Package

glyphs

Source

glyphs.lisp (file)


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

5.1.2 Macros

Macro: ± A B
Package

glyphs

Source

glyphs.lisp (file)

Macro: ƒ NAME &rest REST

Similar to defun, requires using x as the default case

Package

glyphs

Source

glyphs.lisp (file)

Macro: ƒƒ NAME &rest REST

PS - Similar to defun, requires using x as the default case

Package

glyphs

Source

glyphs.lisp (file)

Macro: ƒ→ NAME TYPES &rest REST

Similar to defun, requires using α as the default case. Includes the type safety of defn.

Package

glyphs

Source

glyphs.lisp (file)

Macro: λ &rest REST

Similar to lambda, requires using x as the default case

Package

glyphs

Source

glyphs.lisp (file)

Macro: λλ &rest REST

PS - Similar to lambda, requires using x as the default case

Package

glyphs

Source

glyphs.lisp (file)

Macro: ψ DATA &rest REST

Shortcut for a mapcar with the short lambda stuff

Package

glyphs

Source

glyphs.lisp (file)


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

5.2 Internal definitions


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

5.2.1 Macros

Macro: /. &rest REST
Package

glyphs

Source

glyphs.lisp (file)

Macro: /./. &rest REST
Package

glyphs

Source

glyphs.lisp (file)

Macro: arg-walker &rest ARGS
Package

glyphs

Source

glyphs.lisp (file)

Macro: defn NAME TYPES ARGS &rest REST

Type safe defun

Package

glyphs

Source

glyphs.lisp (file)

Macro: ff &rest REST
Package

glyphs

Source

glyphs.lisp (file)

Macro: pm NAME ARGS &rest REST
Package

glyphs

Source

glyphs.lisp (file)


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

5.2.2 Functions

Function: flatten STRUCTURE
Package

glyphs

Source

glyphs.lisp (file)

Function: greplace STREAM CHAR
Package

glyphs

Source

glyphs.lisp (file)

Function: gscan STREAM CHAR
Package

glyphs

Source

glyphs.lisp (file)


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

Appendix A Indexes


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

A.1 Concepts

Jump to:   F   G   L  
Index Entry  Section

F
File, Lisp, glyphs.asd: The glyphs<dot>asd file
File, Lisp, glyphs/glyphs.lisp: The glyphs/glyphs<dot>lisp file
File, Lisp, glyphs/package.lisp: The glyphs/package<dot>lisp file

G
glyphs.asd: The glyphs<dot>asd file
glyphs/glyphs.lisp: The glyphs/glyphs<dot>lisp file
glyphs/package.lisp: The glyphs/package<dot>lisp file

L
Lisp File, glyphs.asd: The glyphs<dot>asd file
Lisp File, glyphs/glyphs.lisp: The glyphs/glyphs<dot>lisp file
Lisp File, glyphs/package.lisp: The glyphs/package<dot>lisp file

Jump to:   F   G   L  

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

A.2 Functions

Jump to:   /   ±  
A   D   F   G   M   P   Ƒ   Λ   Ψ  
Index Entry  Section

/
/.: Internal macros
/./.: Internal macros

±
±: Exported macros

A
arg-walker: Internal macros

D
defn: Internal macros

F
ff: Internal macros
flatten: Internal functions
Function, flatten: Internal functions
Function, greplace: Internal functions
Function, gscan: Internal functions

G
greplace: Internal functions
gscan: Internal functions

M
Macro, /.: Internal macros
Macro, /./.: Internal macros
Macro, arg-walker: Internal macros
Macro, defn: Internal macros
Macro, ff: Internal macros
Macro, pm: Internal macros
Macro, ±: Exported macros
Macro, ƒ: Exported macros
Macro, ƒƒ: Exported macros
Macro, ƒ→: Exported macros
Macro, λ: Exported macros
Macro, λλ: Exported macros
Macro, ψ: Exported macros

P
pm: Internal macros

Ƒ
ƒ: Exported macros
ƒƒ: Exported macros
ƒ→: Exported macros

Λ
λ: Exported macros
λλ: Exported macros

Ψ
ψ: Exported macros

Jump to:   /   ±  
A   D   F   G   M   P   Ƒ   Λ   Ψ  

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

A.3 Variables

Jump to:   *  
S  
Index Entry  Section

*
*ψ*: Exported special variables

S
Special Variable, *ψ*: Exported special variables

Jump to:   *  
S  

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

A.4 Data types

Jump to:   G   P   S  
Index Entry  Section

G
glyphs: The glyphs system
glyphs: The glyphs package

P
Package, glyphs: The glyphs package

S
System, glyphs: The glyphs system

Jump to:   G   P   S