The cl-indeterminism Reference Manual

Table of Contents

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

The cl-indeterminism Reference Manual

This is the cl-indeterminism Reference Manual, version 0.3, generated automatically by Declt version 2.3 "Robert April" on Tue Jan 09 13:43:59 2018 GMT+0.


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

1 Introduction

cl-indeterminism

Do some cool stuff with undefined functions and variables.

By now, 'cool stuff' includes:

Finding

Codewalk the form and find, which variables and functions are undefined.

CL-USER> (ql:quickload 'cl-indeterminism)
CL-USER> (cl-indeterminism:find-undefs '(foo bar baz))
((:FUNCTIONS FOO) (:VARIABLES BAZ BAR))

FIND-UNDEFS is now a macro which expands in the surrounding context, making it possible to catch undefined variables relative to the current lexenv.

CL-USER> (let ((a 1)) (cl-indeterminism:find-undefs 'a))
((:FUNCTIONS) (:VARIABLES))

Still, one can explicitly specify to find undefs with respect to top-level environment

CL-USER> (let ((a 1)) (cl-indeterminism:find-undefs 'a :env :null))
((:FUNCTIONS) (:VARIABLES A))

Can be also used to find list of undefined variables at compile time

(defmacro list-the-undefs (&body body &environment env)
  `(list ,@(mapcar (lambda (x) `(quote ,x))
		   (find-undefs `(progn ,@body) :env env))))
(let ((bar 1)) (declare (ignore bar)) (find-undefs '(foo bar baz)))
((:FUNCTIONS FOO) (:VARIABLES BAZ))

Uses profound HU.DWIM.WALKER system to do the heavy lifting of code walking and is, in fact, just a convenience wrapper around it.

Note: if your implementation is not supported by HU.DWIM.WALKER or CL-CURLEX, then branch "without-curlex" is for you - there initial unsophisticated behaviour of the system is fixed forever.

Transforming

Codewalk the form and transform undefined variables and functions in it on the fly to something else. Has a side effect of expanding all the macros in the form.

CL-USER> (ql:quickload 'cl-indeterminism)
CL-USER> (let ((cl-indeterminism:*variable-transformer* (lambda (x) `(quote ,x))))
           (cl-indeterminism:macroexpand-all-transforming-undefs '(a b c)))
(A 'B 'C)
CL-USER> (let ((cl-indeterminism:*function-transformer*
                (lambda (form)
                  (if (keywordp (car form))
                      (cl-indeterminism:fail-transform)
                      `(,(intern (string (car form)) "KEYWORD")
                        ,@(cdr form))))))
           (cl-indeterminism:macroexpand-all-transforming-undefs '(a b c)))
(:A B C)

The API consists of the following ingredients:

I personally plan to use all this machinery in my fork of ESRAP packrat parser (https://github.com/mabragor/esrap). There, the idea is to transform all undefined variable names inside DEFRULE macro into calls to functions, which try to continue parsing with help of a rule, corresponding to the name of undefined variable. See branch 'liquid' there for examples of usage of MACROEXPAND-ALL-TRANSFORMING-UNDEFS.

Transforming at compile-time

Works similar to transforming at runtime, but is far more interesting, isn't it?

CL-USER> (ql:quickload 'cl-indeterminism)
CL-USER> (defmacro autoquote (form &environment env)
           (let ((cl-indeterminism:*variable-transformer* (lambda (x) `(quote ,x))))
             (cl-indeterminism:macroexpand-cc-all-transforming-undefs form :env env)))
;; So, our AUTOQUOTE macro automatically quotes
;; all the undefined variables inside its form
CL-USER> (defun foo ()
           (autoquote (list b c)))
CL-USER> (foo)
(B C)
;; And it takes into account lexical environment
;; it is expanded in, so here B is not quoted
CL-USER> (let ((b 1))
           (defun foo ()
             (autoquote (list b c))))
CL-USER> (foo)
(1 C)

Note, that lexical environment has to be explicitly fetched with help of &ENVIRONMENT keyword of the enclosing macro and passed to MACROEXPAND-CC-ALL-TRANSFORMING-UNDEFS. This is due to my failure to fetch this compile environment in some implementations with some other tricks.

TODO:

BUGS & GOTCHAS:


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 cl-indeterminism

Author

Alexander Popolitov <popolit@gmail.com>

License

GPL

Description

Find and/or manipulate undefined variables and functions in the form.

Version

0.3

Dependencies
Source

cl-indeterminism.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 cl-indeterminism.asd

Location

cl-indeterminism.asd

Systems

cl-indeterminism (system)


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

3.1.2 cl-indeterminism/cl-indeterminism.lisp

Parent

cl-indeterminism (system)

Location

cl-indeterminism.lisp


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

3.1.3 cl-indeterminism/package.lisp

Dependency

cl-indeterminism.lisp (file)

Parent

cl-indeterminism (system)

Location

package.lisp

Packages

cl-indeterminism


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

4 Packages

Packages are listed by definition order.


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

4.1 cl-indeterminism

Source

package.lisp (file)

Use List

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
cl-indeterminism.asd: The cl-indeterminism<dot>asd file
cl-indeterminism/cl-indeterminism.lisp: The cl-indeterminism/cl-indeterminism<dot>lisp file
cl-indeterminism/package.lisp: The cl-indeterminism/package<dot>lisp file

F
File, Lisp, cl-indeterminism.asd: The cl-indeterminism<dot>asd file
File, Lisp, cl-indeterminism/cl-indeterminism.lisp: The cl-indeterminism/cl-indeterminism<dot>lisp file
File, Lisp, cl-indeterminism/package.lisp: The cl-indeterminism/package<dot>lisp file

L
Lisp File, cl-indeterminism.asd: The cl-indeterminism<dot>asd file
Lisp File, cl-indeterminism/cl-indeterminism.lisp: The cl-indeterminism/cl-indeterminism<dot>lisp file
Lisp File, cl-indeterminism/package.lisp: The cl-indeterminism/package<dot>lisp file

Jump to:   C   F   L  

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

A.2 Functions


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
cl-indeterminism: The cl-indeterminism system
cl-indeterminism: The cl-indeterminism package

P
Package, cl-indeterminism: The cl-indeterminism package

S
System, cl-indeterminism: The cl-indeterminism system

Jump to:   C   P   S