The polisher Reference Manual

Table of Contents

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

The polisher Reference Manual

This is the polisher Reference Manual, version 0.1, generated automatically by Declt version 3.0 "Montgomery Scott" on Wed Oct 13 12:10:44 2021 GMT+0.


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

1 Introduction

Build Status License GitHub code size in bytes

Polisher

Infix notation to S-expression (Polish notation) translator for Common Lisp

Overview

Formulae inside the reader macro #i{ ... } are interpreted as infix notation. If you don't want to use it, the macro polish is available instead.

(polisher:activate-infix-syntax)  ; Activate #i{ ... } reader macro

#i{1+2*3}
;=> 7

(polisher:polish "1+2*3") ; Exactly the same as the above one
;=> 7

#i{1 + 2*3} ; Spaces can be inserted anywhere
;=> 7

#i{2*3/4}
;=> 3/2

#i{2**2**3} ; Identical to 2**(2**3), not (2**2)**3
;=> 256

#i{atan(1.0d0, 1.0d0)}
;=> 0.7853981633974483d0

(flet ((add1 (x) (+ x 1)))
  #i{add1(2)+3})
;=> 6

(defparameter *some-global-value* 1.5) ; The symbol containg operator charcters
#i{1 + 2 * "*some-global-value*"}      ; must be double-quoted
;=> 4.0

#i{2*#c(1 2)+3}
;=> #C(5 4)

#i{#b101 +3} ; Some spaces are needed after #b101
;=> 8

Installation

Quicklisp

If you already have Quicklisp client, just run the following:

(ql:quickload :polisher)

It will resolve dependencies automatically.

Github and Quicklisp

  1. Clone or download the latest version from GitHub.
  2. In the cloned directory, run (ql:register-local-projects).
  3. Now you can use (ql:quickload :polisher) anywhere.

ASDF

  1. Clone or download the latest version from GitHub.
  2. Place the directory where your ASDF system can find.
  3. Run (asdf:load-system :polisher).

Requirements

Default operators

Following operators are defined by default:

| symbol | function | priority | left associative | |--------|----------|----------|------------------| | + | + | 1 | t | | - | - | 1 | t | | * | * | 2 | t | | / | / | 2 | t | | ** | expt | 3 | nil |

Add your own operator

(polisher:add-operator (make-instance 'polisher:operator
                                      :symbol '^
                                      :function 'expt
                                      :priority 3
                                      :left-associative nil))

#i{2^2^3}
;=> 256

Note that if there are left-associative operators and right-associative operators both having the same priority, formulae can't be evaluated correctly. For example, when op1 is left-associative and op2 is right-associative, x op1 y op2 z can be interpreted as either (x op1 y) op2 z and x op1 (y op2 z).

When you add your own operator, be careful of which package its symbol is interned in.

Restrictions

Symbols start with numbers

Symbols which start with numbers must be double-quoted. The following example shows the reason:

(let ((1e 2))
  #i{1e+1+1})
;=> 11.0

(let ((1e 2))
  #i{"1e"+1+1})
;=> 4

No one defines such an odd symbol? Remember the standard functions 1+ and 1-!

Symbols with vertical bars

Symbols whose symbol-name sandwiched in vertical bars (e.g. |ab de|) can't be used. This is because someone may want to use a vertical bar as the logical OR operator.

Double-quoting is necessary?

The infix formula 1+*global-symbol* can be uniquely interpreted as (+ 1 *global-symbol*), so double-quoting may be unnecessary. However in my opinion, the formula seems very weird when it appears in ALGOL-like languages; so I think double-quoting should be used. In addition, many text editors highlight double-quoted things, helping us to distinguish symbol-names from operators.

License

MIT

Author

mrcdr


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 polisher

Author

mrcdr

Home Page

https://github.com/mrcdr/polisher

License

MIT

Description

Infix notation to S-expression translator

Version

0.1

Dependency

cl-ppcre

Source

polisher.asd (file)

Components

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

3 Modules

Modules are listed depth-first from the system components tree.


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

3.1 polisher/src

Dependency

package.lisp (file)

Parent

polisher (system)

Location

src/

Components

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

4 Files

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


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

4.1 Lisp


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

4.1.1 polisher.asd

Location

polisher.asd

Systems

polisher (system)


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

4.1.2 polisher/package.lisp

Parent

polisher (system)

Location

package.lisp

Packages

polisher


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

4.1.3 polisher/src/types-svalues.lisp

Parent

src (module)

Location

src/types-svalues.lisp

Exported Definitions
Internal Definitions

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

4.1.4 polisher/src/tokenizer.lisp

Dependency

types-svalues.lisp (file)

Parent

src (module)

Location

src/tokenizer.lisp

Internal Definitions

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

4.1.5 polisher/src/transformer.lisp

Dependency

tokenizer.lisp (file)

Parent

src (module)

Location

src/transformer.lisp

Internal Definitions

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

4.1.6 polisher/src/interface.lisp

Dependency

transformer.lisp (file)

Parent

src (module)

Location

src/interface.lisp

Exported Definitions
Internal Definitions

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

5 Packages

Packages are listed by definition order.


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

5.1 polisher

Source

package.lisp (file)

Use List

common-lisp

Exported Definitions
Internal Definitions

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

6 Definitions

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


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

6.1 Exported definitions


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

6.1.1 Macros

Macro: polish FORMULA-STR

Convert given infix-style formula into S-expression, which will be evaluated as usual lisp form.

Package

polisher

Source

interface.lisp (file)


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

6.1.2 Functions

Function: activate-infix-syntax &optional ACTIVATE DISPATCH-CHAR

Activate infix reader-macro #i{...} by default. If the argument "activate" is nil,
deactivate (unregister) #i macro (regardless of whether or not it has been registered by this function). The macro character "i" can be changed by the argument "dispatch-char".

Package

polisher

Source

interface.lisp (file)

Function: add-operator OP

Add infix-style operator, which should be a polisher:operator instance.

Package

polisher

Source

types-svalues.lisp (file)

Function: list-operators ()

Return information of registered operators as string.

Package

polisher

Source

interface.lisp (file)


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

6.1.3 Classes

Class: operator ()

Operator class, whose instance will usually be registered by polisher:add-operator function.

Package

polisher

Source

types-svalues.lisp (file)

Direct superclasses

standard-object (class)

Direct methods
  • readable-string (method)
  • print-object (method)
  • initialize-instance (method)
Direct slots
Slot: symbol

Symbol used in infix-style.

Type

(quote symbol)

Initargs

:symbol

Slot: function

Function to be called, which must receive exactly two arguments.

Initargs

:function

Slot: priority

Operator priority. Operators will be evaluated from ones having larger priority.

Type

(quote number)

Initargs

:priority

Slot: left-associative

If t, this operator will be left associative (e.g. addition operator +). If nil, this operator will be right associative (e.g. power operator **).

Type

(quote boole)

Initargs

:left-associative

Initform

t


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

6.2 Internal definitions


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

6.2.1 Special variables

Special Variable: *left-paren*
Package

polisher

Source

types-svalues.lisp (file)

Special Variable: *max-priority*
Package

polisher

Source

types-svalues.lisp (file)

Special Variable: *operator-list*
Package

polisher

Source

types-svalues.lisp (file)

Special Variable: *right-paren*
Package

polisher

Source

types-svalues.lisp (file)

Special Variable: *separator*
Package

polisher

Source

types-svalues.lisp (file)


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

6.2.2 Macros

Macro: acond &rest CLAUSES
Package

polisher

Source

tokenizer.lisp (file)


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

6.2.3 Functions

Function: create-operator-regex ()
Package

polisher

Source

tokenizer.lisp (file)

Function: find-split-point FORMULA BEGIN END
Package

polisher

Source

transformer.lisp (file)

Function: infix-to-sexp FORMULA-STR
Package

polisher

Source

interface.lisp (file)

Function: match-length REGEX TARGET-STRING &optional GROUP-INDEX
Package

polisher

Source

tokenizer.lisp (file)

Function: parse-formula FORMULA BEGIN END
Package

polisher

Source

transformer.lisp (file)

Function: parse-value-or-function FORMULA BEGIN END
Package

polisher

Source

transformer.lisp (file)

Function: read-formula STREAM END-CHAR
Package

polisher

Source

interface.lisp (file)

Function: read-safely STR
Package

polisher

Source

tokenizer.lisp (file)

Function: should-be-peeled FORMULA BEGIN END
Package

polisher

Source

transformer.lisp (file)

Function: symbol-to-operator SYMBOL
Package

polisher

Source

types-svalues.lisp (file)

Function: tokenize FORMULA-STR
Package

polisher

Source

tokenizer.lisp (file)

Function: transform-into-sexp FORMULA
Package

polisher

Source

transformer.lisp (file)


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

6.2.4 Generic functions

Generic Function: readable-string OBJECT
Package

polisher

Source

types-svalues.lisp (file)

Methods
Method: readable-string (OBJECT operator)

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

Appendix A Indexes


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

A.1 Concepts

Jump to:   F   L   M   P  
Index Entry  Section

F
File, Lisp, polisher.asd: The polisher․asd file
File, Lisp, polisher/package.lisp: The polisher/package․lisp file
File, Lisp, polisher/src/interface.lisp: The polisher/src/interface․lisp file
File, Lisp, polisher/src/tokenizer.lisp: The polisher/src/tokenizer․lisp file
File, Lisp, polisher/src/transformer.lisp: The polisher/src/transformer․lisp file
File, Lisp, polisher/src/types-svalues.lisp: The polisher/src/types-svalues․lisp file

L
Lisp File, polisher.asd: The polisher․asd file
Lisp File, polisher/package.lisp: The polisher/package․lisp file
Lisp File, polisher/src/interface.lisp: The polisher/src/interface․lisp file
Lisp File, polisher/src/tokenizer.lisp: The polisher/src/tokenizer․lisp file
Lisp File, polisher/src/transformer.lisp: The polisher/src/transformer․lisp file
Lisp File, polisher/src/types-svalues.lisp: The polisher/src/types-svalues․lisp file

M
Module, polisher/src: The polisher/src module

P
polisher.asd: The polisher․asd file
polisher/package.lisp: The polisher/package․lisp file
polisher/src: The polisher/src module
polisher/src/interface.lisp: The polisher/src/interface․lisp file
polisher/src/tokenizer.lisp: The polisher/src/tokenizer․lisp file
polisher/src/transformer.lisp: The polisher/src/transformer․lisp file
polisher/src/types-svalues.lisp: The polisher/src/types-svalues․lisp file

Jump to:   F   L   M   P  

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

A.2 Functions

Jump to:   A   C   F   G   I   L   M   P   R   S   T  
Index Entry  Section

A
acond: Internal macros
activate-infix-syntax: Exported functions
add-operator: Exported functions

C
create-operator-regex: Internal functions

F
find-split-point: Internal functions
Function, activate-infix-syntax: Exported functions
Function, add-operator: Exported functions
Function, create-operator-regex: Internal functions
Function, find-split-point: Internal functions
Function, infix-to-sexp: Internal functions
Function, list-operators: Exported functions
Function, match-length: Internal functions
Function, parse-formula: Internal functions
Function, parse-value-or-function: Internal functions
Function, read-formula: Internal functions
Function, read-safely: Internal functions
Function, should-be-peeled: Internal functions
Function, symbol-to-operator: Internal functions
Function, tokenize: Internal functions
Function, transform-into-sexp: Internal functions

G
Generic Function, readable-string: Internal generic functions

I
infix-to-sexp: Internal functions

L
list-operators: Exported functions

M
Macro, acond: Internal macros
Macro, polish: Exported macros
match-length: Internal functions
Method, readable-string: Internal generic functions

P
parse-formula: Internal functions
parse-value-or-function: Internal functions
polish: Exported macros

R
read-formula: Internal functions
read-safely: Internal functions
readable-string: Internal generic functions
readable-string: Internal generic functions

S
should-be-peeled: Internal functions
symbol-to-operator: Internal functions

T
tokenize: Internal functions
transform-into-sexp: Internal functions

Jump to:   A   C   F   G   I   L   M   P   R   S   T  

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

A.3 Variables

Jump to:   *  
F   L   P   S  
Index Entry  Section

*
*left-paren*: Internal special variables
*max-priority*: Internal special variables
*operator-list*: Internal special variables
*right-paren*: Internal special variables
*separator*: Internal special variables

F
function: Exported classes

L
left-associative: Exported classes

P
priority: Exported classes

S
Slot, function: Exported classes
Slot, left-associative: Exported classes
Slot, priority: Exported classes
Slot, symbol: Exported classes
Special Variable, *left-paren*: Internal special variables
Special Variable, *max-priority*: Internal special variables
Special Variable, *operator-list*: Internal special variables
Special Variable, *right-paren*: Internal special variables
Special Variable, *separator*: Internal special variables
symbol: Exported classes

Jump to:   *  
F   L   P   S  

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

A.4 Data types

Jump to:   C   O   P   S  
Index Entry  Section

C
Class, operator: Exported classes

O
operator: Exported classes

P
Package, polisher: The polisher package
polisher: The polisher system
polisher: The polisher package

S
System, polisher: The polisher system

Jump to:   C   O   P   S