
Optimization by s-expression transformation
auto-permute-typecase macro
Clauses can be reordered after rewriting, maintaining semantics.
Result of simplification depends on order of clauses.
Using a heuristic-cost function we can compare semantically
equivalent expansions.
Implementation of auto-permute-typecase macro.
( de fm ac ro auto −perm ute− t ypec ase ( o b j &r e s t c l a u s e s )
( l e t (( b e s t− o r d e r ( h e u r i s t i c − c o s t c l a u s e s ) )
( c l a u s e s ( s i m p l i f y ( r e w r i t e c l a u s e s ) ) ) )
( map−permutations ( perm c l a u s e s )
( l e t (( c a n d i d a t e ( s i m p l i f y ( f o r w a r d − s u b s t i t u t e perm ) ) ) )
( when (< ( h e u r i s t i c − c o s t c a n d i d a t e )
( h e u r i s t i c − c o s t b e s t − o r d e r ) )
( s e t f b e s t − o r d e r c a n d i d a t e ) ) ) )
( l i s t ∗ ’ t y p e c a s e o b j b e s t − o r d e r ) ) )
Finds permutation of clauses with minimum cost
Jim Newton (11th European Lisp Symposium) Strategies for typecase optimization 16-17 April 2017 23 / 41