Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/guicho271828/inner-conditional

Series of macros which optimizes the inner conditional jumps of looping, iterating, anything
https://github.com/guicho271828/inner-conditional

Last synced: 29 days ago
JSON representation

Series of macros which optimizes the inner conditional jumps of looping, iterating, anything

Awesome Lists containing this project

README

        

* Inner-Conditional

+ Series of macros which help users optimize the conditional jumps in a inner loop
+ The interface is similar to the continuation, so I call it as `compile-time continuation’.
Everything is implemented in compile-time so theres no performance drawbacks in run-time
+ Extensible syntaxes and helper macros for other implementers of libraries, especially for
the macro writers or the heavy lambda-lovers. Provides a standardized way to minimize the number of condition check

* Recent changes

+ It does not use =macrolet= and =symbol-macrolet= anymore, which means
it can be used with =iterate= library. (2013/5/3)
+ This library is not well maintained now. Please (?) don't use it.
+ I think I will reerite it with [[https://github.com/guicho271828/recursive-macroexpansion][recursive-macroexpansion]].

* Basic Usage

The condition checking is done only once.
#+BEGIN_SRC LISP
(ql:quickload :iterate)
(use-package :iterate)

(defun test0 (flag)
(with-inner (body)
(iter (for i from 0 to 5)
(print i)
(inner (body)
(if flag
(body (princ "loop on"))
(body (princ "loop off")))))))

INNER-CONDITIONAL-TEST> (test0 t)

0 loop on
1 loop on
2 loop on
3 loop on
4 loop on
5 loop on
#+END_SRC

* Concepts and API

Removing conditional jumps in loops are one of the easiest way to
optimize the loop. The number of checks should be minimized, and the
checking variables in a smaller loop may well be a large
bottleneck. Yet, some code would yield a bad-looking result of that
optimization, since the semantics of the code best fits the code which
has conditional jumps in a smaller loop. Luckily, Common Lisp has
macros, which provides the ability to walk on and modify the code
tree. So we can keep the code clean and at the same time get a
faster result.

For more details, see /Concepts and API/ (https://github.com/guicho271828/inner-conditional/blob/master/concepts-and-api.org)

* Use with your own library

If you write a macro which expands to a code which always checks a
certain dynamic variable then this library may help you write an
extension which minimizes the number of checks in the expanded code.

For more details, see /Use with your own library/ (https://github.com/guicho271828/inner-conditional/blob/master/use-with-your-own-library.org)

* Optimization Results

The effect of this library may seem trivial, but still I try to show
you an optimization results with trivial examples. Any other result
reports are welcome! Because I don't came up with other
truly-performance-sensitive examples.

For more details, see /Optimization Results/ (https://github.com/guicho271828/inner-conditional/blob/master/opt-results.org)

* Misc

** Dependencies

This library is at least tested on implementation listed below:

+ SBCL 1.1.2 on X86-64 Linux 3.2.0-39-generic (author's environment)

Also, it depends on the following libraries:

+ ITERATE ::
Jonathan Amsterdam's iterator/gatherer/accumulator facility

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

+ CL-ANNOT by Tomohiro Matsuyama ::
Python-like Annotation Syntax for Common Lisp

+ CL-SYNTAX by m2ym ::
Reader Syntax Coventions for Common Lisp and SLIME

+ Optima by m2ym ::
Optimized Pattern Matching Library for Common Lisp

** Installation

+ First grab the code with =git clone git://github.com/guicho271828/inner-conditional.git=
+ Put it in your local-project folder
+ open slime REPL
+ =(ql:register-local-projects)=
+ =(ql:quickload :inner-conditional)= and the library will be
installed along with the dependencies

** Author

+ Masataro Asai ([email protected])

** Copyright

Copyright (c) 2013 Masataro Asai ([email protected])

** License

Licensed under the LLGPL License.