Outdated egg!

This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

Premature optimization is the root of all evil!

These macros will double your code size! Use at your own risk!

_But_ if you need speed enough that you're going to write special cases anyway, using these macros will at least make that a little cleaner and more manageable.

[syntax] (with-special-cased-procedures ((var predefined) ...) body ...)

Examples:

Defines the SRFI-1 `member' procedure with optional equality argument, but duplicates the inner loop conditioned on eq, special-casing one on the eq? case.

(define (member key ls . o)
  (let ((eq (if (pair? o) (car o) equal?)))
    (with-special-cased-procedures ((eq eq?))
      (let lp ((ls ls))
        (cond
         ((null? ls)
          #f)
         ((eq key (car ls))
          ls)
         (else
          (lp (cdr ls))))))))

Defines a for-each variation that optionally writes trace output every 100 elements. Two versions of the inner loop get created, one with and one without the tracing call, so that there's no extra overhead when not tracing.

(define (for-each/trace proc ls . o)
  (with-special-cased-conditional (trace? (and (pair? o) (car o)))
    (let lp ((ls ls) (i 0))
      (if (and (trace?) (zero? (modulo i 100)))
          (print "iteration: " i))
      (cond
       ((pair? ls)
        (proc (car ls))
        (lp (cdr ls) (+ i 1)))))))