The type-i Reference Manual

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

The type-i Reference Manual

This is the type-i Reference Manual, version 0.1, generated automatically by Declt version 4.0 beta 2 "William Riker" on Mon Aug 15 06:05:27 2022 GMT+0.

Table of Contents


1 Introduction


* Type-I : type-inference from a predicate

This library tries to provide a way to detect what kind of type the given
predicate is trying to check. *This is different from inferring the return
type of a function.* For example,

#+BEGIN_SRC lisp

(eq 'null (test-type '(eql nil ?)))

(eq 'string (test-type '(stringp ?)))

#+END_SRC

The inference is done on form basis, and the equivalence of predicates are
determined by =#'equal=. To simplify the design, the argument to check
should be a symbol =?=, exported in package =type-i=.

Function =test-type= returns the inferred type. In contrast, =type-tests=
returns a list of all possible test predicates that returns true when =?=
is bound to the object of interest.

#+BEGIN_SRC lisp
  (is (subset '((TYPEP ? 'integer)
                (integerp ?))
              (type-tests 'integer)))

  ;; more inference on integers, e.g., (< 0 ? 4), should be added
  (is (subset '((TYPEP ? '(mod 5))
                (TYPEP ? '(integer 0 4)))
              (type-tests '(mod 5))))

#+END_SRC

This library is extensible. with =define-inference-rule= macro, you can add
more inferers to improve this library. Each inference rule is a unary
function that takes a predicate form, then returns a list of more
forms.

The =test-type= searches in the form space, adding the results of each
inference rule, until a form =(typep ? X)= is found (where X is
unknown). If it fails to find such a form even if the maximal set
is obtained, then the =test-type= returns nil. =type-tests= just returns
the maximal set.

I currently implemented the following inference rules:

- typep -- =(typep ? 'array)= -> =(arrayp ?)= etc.
- unary -- =(arrayp ?)= -> =(typep ? 'array) (typep ? '(array)) (typep ?
  '(array *))= ...
- null -- =(null ?) (typep ? null) (eql ? nil) (eql nil ?) (eq ? nil)= ...
- derived -- call =typexpand=

Inference on exhaustive partitions, e.g., =(typep ? 'list)= -> =(typep ?
'(or cons null))= is planned.

** Dependencies

This library is at least tested on implementation listed below:

+ SBCL 1.2.8 on X86-64 Linux  3.13.0-46-generic (author's environment)

Also, it depends on the following libraries:

+ Trivia by Masataro Asai ::
     NON-Optimized Pattern Matching Library

+ alexandria by  ::
    Alexandria is a collection of portable public domain utilities.

+ iterate by  ::
    Jonathan Amsterdam's iterator/gatherer/accumulator facility

+ introspect-environment by Bike  ::
    Small interface to portable but nonstandard introspection of CL environments.



** Author

+ Masataro Asai (guicho2.71828@gmail.com)

* Copyright

Copyright (c) 2015 Masataro Asai (guicho2.71828@gmail.com)


* License

Licensed under the LLGPL License.





2 Systems

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


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

2.1 type-i

Type Inference Utility on Fundamentally 1-arg Predicates

Author

Masataro Asai

Contact

guicho2.71828@gmail.com

License

LLGPL

Version

0.1

Dependencies
  • introspect-environment (system).
  • alexandria (system).
  • trivia.trivial (system).
  • lisp-namespace (system).
Source

type-i.asd.

Child Components

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 type-i/type-i.asd

Source

type-i.asd.

Parent Component

type-i (system).

ASDF Systems

type-i.


3.1.2 type-i/package.lisp

Source

type-i.asd.

Parent Component

type-i (system).

Packages

type-i.

Public Interface
Internals

3.1.3 type-i/infer-typep.lisp

Dependency

package.lisp (file).

Source

type-i.asd.

Parent Component

type-i (system).

Internals

3.1.4 type-i/infer-unary.lisp

Dependency

infer-typep.lisp (file).

Source

type-i.asd.

Parent Component

type-i (system).

Internals

typep-form (function).


3.1.5 type-i/infer-derived.lisp

Dependency

infer-unary.lisp (file).

Source

type-i.asd.

Parent Component

type-i (system).


3.1.6 type-i/infer-constants.lisp

Dependency

infer-derived.lisp (file).

Source

type-i.asd.

Parent Component

type-i (system).

Internals

+null-tests+ (special variable).


3.1.7 type-i/infer-compound.lisp

Dependency

infer-constants.lisp (file).

Source

type-i.asd.

Parent Component

type-i (system).


3.1.8 type-i/infer-numbers.lisp

Dependency

infer-compound.lisp (file).

Source

type-i.asd.

Parent Component

type-i (system).


4 Packages

Packages are listed by definition order.


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

4.1 type-i

Source

package.lisp.

Use List
  • alexandria.
  • common-lisp.
  • introspect-environment.
  • trivia.level2.
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


5.1.1 Macros

Macro: define-inference-rule (name args &body body)
Package

type-i.

Source

package.lisp.


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

5.1.2 Ordinary functions

Function: ? (symbol test)

substitute symbol with ’?, canonicalizing the test form amenable for comparison

Package

type-i.

Source

package.lisp.

Function: test-type (test &optional verbose)

infer the type which the given test form is trying to test against.
If the values are NIL,T , it means the type is definitely NIL.
If the values are NIL,NIL , it means the type is not successfully inferred.

Package

type-i.

Source

package.lisp.

Function: type-tests (type &optional verbose)
Package

type-i.

Source

package.lisp.


5.2 Internals


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

5.2.1 Special variables

Special Variable: *compound-infer-level*
Package

type-i.

Source

infer-typep.lisp.

Special Variable: *inference-rules-doc-table*
Package

type-i.

Source

package.lisp.

Special Variable: *inference-rules-table*
Package

type-i.

Source

package.lisp.

Special Variable: *max-compound-type-arguments*
Package

type-i.

Source

infer-typep.lisp.

Special Variable: +null-tests+
Package

type-i.

Source

infer-constants.lisp.


5.2.2 Macros

Macro: inference-rules-let (bindings &body body)
Package

type-i.

Source

package.lisp.


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

5.2.3 Ordinary functions

Function: all-compound-types (compound &optional *compound-infer-level*)
Package

type-i.

Source

infer-typep.lisp.

Function: inference-rules-boundp (symbol)

Automatically defined boolean function.

Package

type-i.

Source

package.lisp.

Function: predicate-p (type)
Package

type-i.

Source

infer-typep.lisp.

Function: predicate-p-function (type)
Package

type-i.

Source

infer-typep.lisp.

Function: predicatep (type)
Package

type-i.

Source

infer-typep.lisp.

Function: predicatep-function (type)
Package

type-i.

Source

infer-typep.lisp.

Function: symbol-inference-rules (symbol &optional default)

Automatically defined getter function. When DEFAULT is supplied, the value is set automatically.

Package

type-i.

Source

package.lisp.

Function: (setf symbol-inference-rules) (symbol)

Automatically defined setter function.

Package

type-i.

Source

package.lisp.

Function: typep-form (typesym)
Package

type-i.

Source

infer-unary.lisp.

Function: valid-type-specifier-p (object)
Package

type-i.

Source

infer-typep.lisp.


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

5.2.4 Conditions

Condition: unbound-inference-rules
Package

type-i.

Source

package.lisp.

Direct superclasses

unbound-variable.


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

5.2.5 Types

Type: inference-rules-type ()
Package

type-i.

Source

package.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   F   I   M   P   S   T   V  
Index Entry  Section

(
(setf symbol-inference-rules): Private ordinary functions

?
?: Public ordinary functions

A
all-compound-types: Private ordinary functions

D
define-inference-rule: Public macros

F
Function, (setf symbol-inference-rules): Private ordinary functions
Function, ?: Public ordinary functions
Function, all-compound-types: Private ordinary functions
Function, inference-rules-boundp: Private ordinary functions
Function, predicate-p: Private ordinary functions
Function, predicate-p-function: Private ordinary functions
Function, predicatep: Private ordinary functions
Function, predicatep-function: Private ordinary functions
Function, symbol-inference-rules: Private ordinary functions
Function, test-type: Public ordinary functions
Function, type-tests: Public ordinary functions
Function, typep-form: Private ordinary functions
Function, valid-type-specifier-p: Private ordinary functions

I
inference-rules-boundp: Private ordinary functions
inference-rules-let: Private macros

M
Macro, define-inference-rule: Public macros
Macro, inference-rules-let: Private macros

P
predicate-p: Private ordinary functions
predicate-p-function: Private ordinary functions
predicatep: Private ordinary functions
predicatep-function: Private ordinary functions

S
symbol-inference-rules: Private ordinary functions

T
test-type: Public ordinary functions
type-tests: Public ordinary functions
typep-form: Private ordinary functions

V
valid-type-specifier-p: Private ordinary functions

Jump to:   (   ?  
A   D   F   I   M   P   S   T   V